Add explicit userId to AppWidget binder calls
Keyguard currently relies on being in the system process to grab the
given user's widgets. When we split keyguard into a new process,
it will need to have access to user-specific info to instantiate a
specific user's widgets. In order to accomplish this, we add an
explicit userid to each binder call as well as new permission
check to allow keyguard access.
This also fixes a potential race condition of having an incorrect user id
due to an async call to change the user. Every binder call now has a specific
user id. The user id is either the calling process user's id or an explicit
one passed by applications like keyguard. It is created once when an
AppWidgetManager is instantiated and remains for the lifetime of the object.
Change-Id: Iec767fb399677b3cf2f9c0993e06b49951eb1f66
diff --git a/src/com/android/settings/KeyguardAppWidgetPickActivity.java b/src/com/android/settings/KeyguardAppWidgetPickActivity.java
index 80dbc0c..8e08019 100644
--- a/src/com/android/settings/KeyguardAppWidgetPickActivity.java
+++ b/src/com/android/settings/KeyguardAppWidgetPickActivity.java
@@ -39,6 +39,7 @@
import android.os.IBinder;
import android.os.RemoteException;
import android.os.ServiceManager;
+import android.os.UserHandle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.IWindowManager;
@@ -515,7 +516,9 @@
if (mAddingToKeyguard && mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
// Found in KeyguardHostView.java
final int KEYGUARD_HOST_ID = 0x4B455947;
- mAppWidgetId = AppWidgetHost.allocateAppWidgetIdForSystem(KEYGUARD_HOST_ID);
+ int userId = ActivityManager.getCurrentUser();
+ mAppWidgetId = AppWidgetHost.allocateAppWidgetIdForSystem(KEYGUARD_HOST_ID,
+ userId);
}
mAppWidgetManager.bindAppWidgetId(
mAppWidgetId, intent.getComponent(), mExtraConfigureOptions);
@@ -579,7 +582,8 @@
} else {
if (mAddingToKeyguard &&
mAppWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) {
- AppWidgetHost.deleteAppWidgetIdForSystem(mAppWidgetId);
+ int userId = ActivityManager.getCurrentUser();
+ AppWidgetHost.deleteAppWidgetIdForSystem(mAppWidgetId, userId);
}
finishDelayedAndShowLockScreen(AppWidgetManager.INVALID_APPWIDGET_ID);
}