Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 91858b0a authored by Hai Zhang's avatar Hai Zhang
Browse files

Use ActivityThread.currentApplication() for application context.

Context.getApplicationContext() might return null if the context is
created with Context.createPackageContextAsUser(), as the application
instance for that context won't be created. In this case we can use
ActivityThread.currentApplication() directly, which does the same
thing as if the context wasn't created for a specific package or user.
We are only using this application context to bind to other services
so it will work fine.

Bug: 131356152
Test: presubmit
Change-Id: Iee1ac9aa088d452dc58dd7f19edc58a3e0b791a6
parent 471ddb2b
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.annotation.NonNull;
import android.annotation.RequiresPermission;
import android.annotation.SystemService;
import android.annotation.UserIdInt;
import android.app.ActivityThread;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -93,7 +94,7 @@ public class RoleControllerManager {
            int userId = context.getUserId();
            RemoteService remoteService = sRemoteServices.get(userId);
            if (remoteService == null) {
                remoteService = new RemoteService(context.getApplicationContext(),
                remoteService = new RemoteService(ActivityThread.currentApplication(),
                        remoteServiceComponentName, handler, userId);
                sRemoteServices.put(userId, remoteService);
            }