Skip to content

Commit 77e95d3

Browse files
Amith YamasaniAndroid (Google) Code Review
authored andcommitted
Merge "Show lockscreen widgets for the current user." into jb-mr1-dev
2 parents 82c8cda + 8fd96ec commit 77e95d3

File tree

3 files changed

+50
-31
lines changed

3 files changed

+50
-31
lines changed

core/java/com/android/internal/widget/LockPatternUtils.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -993,8 +993,8 @@ public boolean isEmergencyCallEnabledWhileSimLocked() {
993993
* or null if there is no next alarm.
994994
*/
995995
public String getNextAlarm() {
996-
String nextAlarm = Settings.System.getString(mContentResolver,
997-
Settings.System.NEXT_ALARM_FORMATTED);
996+
String nextAlarm = Settings.System.getStringForUser(mContentResolver,
997+
Settings.System.NEXT_ALARM_FORMATTED, UserHandle.USER_CURRENT);
998998
if (nextAlarm == null || TextUtils.isEmpty(nextAlarm)) {
999999
return null;
10001000
}
@@ -1021,8 +1021,9 @@ private void setBoolean(String secureSettingKey, boolean enabled) {
10211021

10221022
public int[] getUserDefinedWidgets() {
10231023
int appWidgetId = -1;
1024-
String appWidgetIdString = Settings.Secure.getString(
1025-
mContentResolver, Settings.Secure.LOCK_SCREEN_USER_SELECTED_APPWIDGET_ID);
1024+
String appWidgetIdString = Settings.Secure.getStringForUser(
1025+
mContentResolver, Settings.Secure.LOCK_SCREEN_USER_SELECTED_APPWIDGET_ID,
1026+
UserHandle.USER_CURRENT);
10261027
if (appWidgetIdString != null) {
10271028
appWidgetId = (int) Integer.decode(appWidgetIdString);
10281029
}
@@ -1032,8 +1033,9 @@ public int[] getUserDefinedWidgets() {
10321033

10331034
public int getStatusWidget() {
10341035
int appWidgetId = -1;
1035-
String appWidgetIdString = Settings.Secure.getString(
1036-
mContentResolver, Settings.Secure.LOCK_SCREEN_STATUS_APPWIDGET_ID);
1036+
String appWidgetIdString = Settings.Secure.getStringForUser(
1037+
mContentResolver, Settings.Secure.LOCK_SCREEN_STATUS_APPWIDGET_ID,
1038+
UserHandle.USER_CURRENT);
10371039
if (appWidgetIdString != null) {
10381040
appWidgetId = (int) Integer.decode(appWidgetIdString);
10391041
}

policy/src/com/android/internal/policy/impl/keyguard/KeyguardStatusViewManager.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import android.content.ContentResolver;
2929
import android.content.Context;
3030
import android.graphics.Typeface;
31+
import android.os.UserHandle;
3132
import android.provider.Settings;
3233
import android.text.TextUtils;
3334
import android.text.format.DateFormat;
@@ -178,9 +179,10 @@ private void updateAlarmInfo() {
178179

179180
private void updateOwnerInfo() {
180181
final ContentResolver res = getContext().getContentResolver();
181-
final boolean ownerInfoEnabled = Settings.Secure.getInt(res,
182-
Settings.Secure.LOCK_SCREEN_OWNER_INFO_ENABLED, 1) != 0;
183-
String text = Settings.Secure.getString(res, Settings.Secure.LOCK_SCREEN_OWNER_INFO);
182+
final boolean ownerInfoEnabled = Settings.Secure.getIntForUser(res,
183+
Settings.Secure.LOCK_SCREEN_OWNER_INFO_ENABLED, 1, UserHandle.USER_CURRENT) != 0;
184+
String text = Settings.Secure.getStringForUser(res, Settings.Secure.LOCK_SCREEN_OWNER_INFO,
185+
UserHandle.USER_CURRENT);
184186
if (ownerInfoEnabled && !TextUtils.isEmpty(text)) {
185187
maybeSetUpperCaseText(mOwnerInfoView, text);
186188
mOwnerInfoView.setVisibility(View.VISIBLE);

services/java/com/android/server/AppWidgetService.java

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.android.server;
1818

19+
import android.app.ActivityManagerNative;
1920
import android.app.AlarmManager;
2021
import android.app.PendingIntent;
2122
import android.appwidget.AppWidgetManager;
@@ -27,6 +28,7 @@
2728
import android.content.IntentFilter;
2829
import android.content.ServiceConnection;
2930
import android.content.pm.PackageManager;
31+
import android.os.Binder;
3032
import android.os.Bundle;
3133
import android.os.IBinder;
3234
import android.os.RemoteException;
@@ -193,66 +195,79 @@ public void onReceive(Context context, Intent intent) {
193195
}, UserHandle.ALL, userFilter, null, null);
194196
}
195197

198+
private int getCallingOrCurrentUserId() {
199+
int callingUid = Binder.getCallingUid();
200+
if (callingUid == android.os.Process.myUid()) {
201+
try {
202+
return ActivityManagerNative.getDefault().getCurrentUser().id;
203+
} catch (RemoteException re) {
204+
return UserHandle.getUserId(callingUid);
205+
}
206+
} else {
207+
return UserHandle.getUserId(callingUid);
208+
}
209+
}
210+
196211
@Override
197212
public int allocateAppWidgetId(String packageName, int hostId) throws RemoteException {
198-
return getImplForUser(UserHandle.getCallingUserId()).allocateAppWidgetId(
213+
return getImplForUser(getCallingOrCurrentUserId()).allocateAppWidgetId(
199214
packageName, hostId);
200215
}
201216

202217
@Override
203218
public void deleteAppWidgetId(int appWidgetId) throws RemoteException {
204-
getImplForUser(UserHandle.getCallingUserId()).deleteAppWidgetId(appWidgetId);
219+
getImplForUser(getCallingOrCurrentUserId()).deleteAppWidgetId(appWidgetId);
205220
}
206221

207222
@Override
208223
public void deleteHost(int hostId) throws RemoteException {
209-
getImplForUser(UserHandle.getCallingUserId()).deleteHost(hostId);
224+
getImplForUser(getCallingOrCurrentUserId()).deleteHost(hostId);
210225
}
211226

212227
@Override
213228
public void deleteAllHosts() throws RemoteException {
214-
getImplForUser(UserHandle.getCallingUserId()).deleteAllHosts();
229+
getImplForUser(getCallingOrCurrentUserId()).deleteAllHosts();
215230
}
216231

217232
@Override
218233
public void bindAppWidgetId(int appWidgetId, ComponentName provider, Bundle options)
219234
throws RemoteException {
220-
getImplForUser(UserHandle.getCallingUserId()).bindAppWidgetId(appWidgetId, provider,
235+
getImplForUser(getCallingOrCurrentUserId()).bindAppWidgetId(appWidgetId, provider,
221236
options);
222237
}
223238

224239
@Override
225240
public boolean bindAppWidgetIdIfAllowed(
226241
String packageName, int appWidgetId, ComponentName provider, Bundle options)
227242
throws RemoteException {
228-
return getImplForUser(UserHandle.getCallingUserId()).bindAppWidgetIdIfAllowed(
243+
return getImplForUser(getCallingOrCurrentUserId()).bindAppWidgetIdIfAllowed(
229244
packageName, appWidgetId, provider, options);
230245
}
231246

232247
@Override
233248
public boolean hasBindAppWidgetPermission(String packageName) throws RemoteException {
234-
return getImplForUser(UserHandle.getCallingUserId()).hasBindAppWidgetPermission(
249+
return getImplForUser(getCallingOrCurrentUserId()).hasBindAppWidgetPermission(
235250
packageName);
236251
}
237252

238253
@Override
239254
public void setBindAppWidgetPermission(String packageName, boolean permission)
240255
throws RemoteException {
241-
getImplForUser(UserHandle.getCallingUserId()).setBindAppWidgetPermission(
256+
getImplForUser(getCallingOrCurrentUserId()).setBindAppWidgetPermission(
242257
packageName, permission);
243258
}
244259

245260
@Override
246261
public void bindRemoteViewsService(int appWidgetId, Intent intent, IBinder connection)
247262
throws RemoteException {
248-
getImplForUser(UserHandle.getCallingUserId()).bindRemoteViewsService(
263+
getImplForUser(getCallingOrCurrentUserId()).bindRemoteViewsService(
249264
appWidgetId, intent, connection);
250265
}
251266

252267
@Override
253268
public int[] startListening(IAppWidgetHost host, String packageName, int hostId,
254269
List<RemoteViews> updatedViews) throws RemoteException {
255-
return getImplForUser(UserHandle.getCallingUserId()).startListening(host,
270+
return getImplForUser(getCallingOrCurrentUserId()).startListening(host,
256271
packageName, hostId, updatedViews);
257272
}
258273

@@ -287,27 +302,27 @@ private AppWidgetServiceImpl getImplForUser(int userId) {
287302

288303
@Override
289304
public int[] getAppWidgetIds(ComponentName provider) throws RemoteException {
290-
return getImplForUser(UserHandle.getCallingUserId()).getAppWidgetIds(provider);
305+
return getImplForUser(getCallingOrCurrentUserId()).getAppWidgetIds(provider);
291306
}
292307

293308
@Override
294309
public AppWidgetProviderInfo getAppWidgetInfo(int appWidgetId) throws RemoteException {
295-
return getImplForUser(UserHandle.getCallingUserId()).getAppWidgetInfo(appWidgetId);
310+
return getImplForUser(getCallingOrCurrentUserId()).getAppWidgetInfo(appWidgetId);
296311
}
297312

298313
@Override
299314
public RemoteViews getAppWidgetViews(int appWidgetId) throws RemoteException {
300-
return getImplForUser(UserHandle.getCallingUserId()).getAppWidgetViews(appWidgetId);
315+
return getImplForUser(getCallingOrCurrentUserId()).getAppWidgetViews(appWidgetId);
301316
}
302317

303318
@Override
304319
public void updateAppWidgetOptions(int appWidgetId, Bundle options) {
305-
getImplForUser(UserHandle.getCallingUserId()).updateAppWidgetOptions(appWidgetId, options);
320+
getImplForUser(getCallingOrCurrentUserId()).updateAppWidgetOptions(appWidgetId, options);
306321
}
307322

308323
@Override
309324
public Bundle getAppWidgetOptions(int appWidgetId) {
310-
return getImplForUser(UserHandle.getCallingUserId()).getAppWidgetOptions(appWidgetId);
325+
return getImplForUser(getCallingOrCurrentUserId()).getAppWidgetOptions(appWidgetId);
311326
}
312327

313328
static int[] getAppWidgetIds(Provider p) {
@@ -321,43 +336,43 @@ static int[] getAppWidgetIds(Provider p) {
321336

322337
@Override
323338
public List<AppWidgetProviderInfo> getInstalledProviders() throws RemoteException {
324-
return getImplForUser(UserHandle.getCallingUserId()).getInstalledProviders();
339+
return getImplForUser(getCallingOrCurrentUserId()).getInstalledProviders();
325340
}
326341

327342
@Override
328343
public void notifyAppWidgetViewDataChanged(int[] appWidgetIds, int viewId)
329344
throws RemoteException {
330-
getImplForUser(UserHandle.getCallingUserId()).notifyAppWidgetViewDataChanged(
345+
getImplForUser(getCallingOrCurrentUserId()).notifyAppWidgetViewDataChanged(
331346
appWidgetIds, viewId);
332347
}
333348

334349
@Override
335350
public void partiallyUpdateAppWidgetIds(int[] appWidgetIds, RemoteViews views)
336351
throws RemoteException {
337-
getImplForUser(UserHandle.getCallingUserId()).partiallyUpdateAppWidgetIds(
352+
getImplForUser(getCallingOrCurrentUserId()).partiallyUpdateAppWidgetIds(
338353
appWidgetIds, views);
339354
}
340355

341356
@Override
342357
public void stopListening(int hostId) throws RemoteException {
343-
getImplForUser(UserHandle.getCallingUserId()).stopListening(hostId);
358+
getImplForUser(getCallingOrCurrentUserId()).stopListening(hostId);
344359
}
345360

346361
@Override
347362
public void unbindRemoteViewsService(int appWidgetId, Intent intent) throws RemoteException {
348-
getImplForUser(UserHandle.getCallingUserId()).unbindRemoteViewsService(
363+
getImplForUser(getCallingOrCurrentUserId()).unbindRemoteViewsService(
349364
appWidgetId, intent);
350365
}
351366

352367
@Override
353368
public void updateAppWidgetIds(int[] appWidgetIds, RemoteViews views) throws RemoteException {
354-
getImplForUser(UserHandle.getCallingUserId()).updateAppWidgetIds(appWidgetIds, views);
369+
getImplForUser(getCallingOrCurrentUserId()).updateAppWidgetIds(appWidgetIds, views);
355370
}
356371

357372
@Override
358373
public void updateAppWidgetProvider(ComponentName provider, RemoteViews views)
359374
throws RemoteException {
360-
getImplForUser(UserHandle.getCallingUserId()).updateAppWidgetProvider(provider, views);
375+
getImplForUser(getCallingOrCurrentUserId()).updateAppWidgetProvider(provider, views);
361376
}
362377

363378
@Override

0 commit comments

Comments
 (0)