use of android.os.UserHandle in project android_frameworks_base by DirtyUnicorns.
the class DevicePolicyManagerService method clearProfileOwner.
@Override
public void clearProfileOwner(ComponentName who) {
if (!mHasFeature) {
return;
}
final UserHandle callingUser = mInjector.binderGetCallingUserHandle();
final int userId = callingUser.getIdentifier();
enforceNotManagedProfile(userId, "clear profile owner");
enforceUserUnlocked(userId);
// Check if this is the profile owner who is calling
final ActiveAdmin admin = getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER);
synchronized (this) {
final long ident = mInjector.binderClearCallingIdentity();
try {
clearProfileOwnerLocked(admin, userId);
removeActiveAdminLocked(who, userId);
} finally {
mInjector.binderRestoreCallingIdentity(ident);
}
Slog.i(LOG_TAG, "Profile owner " + who + " removed from user " + userId);
}
}
use of android.os.UserHandle in project android_frameworks_base by DirtyUnicorns.
the class VoiceInteractionSessionConnection method showLocked.
public boolean showLocked(Bundle args, int flags, int disabledContext, IVoiceInteractionSessionShowCallback showCallback, IBinder activityToken, List<IBinder> topActivities) {
if (mBound) {
if (!mFullyBound) {
mFullyBound = mContext.bindServiceAsUser(mBindIntent, mFullConnection, Context.BIND_AUTO_CREATE | Context.BIND_TREAT_LIKE_ACTIVITY | Context.BIND_FOREGROUND_SERVICE, new UserHandle(mUser));
}
mShown = true;
boolean isAssistDataAllowed = true;
try {
isAssistDataAllowed = mAm.isAssistDataAllowedOnCurrentActivity();
} catch (RemoteException e) {
}
disabledContext |= getUserDisabledShowContextLocked();
boolean structureEnabled = isAssistDataAllowed && (disabledContext & VoiceInteractionSession.SHOW_WITH_ASSIST) == 0;
boolean screenshotEnabled = isAssistDataAllowed && structureEnabled && (disabledContext & VoiceInteractionSession.SHOW_WITH_SCREENSHOT) == 0;
mShowArgs = args;
mShowFlags = flags;
mHaveAssistData = false;
mPendingAssistDataCount = 0;
boolean needDisclosure = false;
if ((flags & VoiceInteractionSession.SHOW_WITH_ASSIST) != 0) {
if (mAppOps.noteOpNoThrow(AppOpsManager.OP_ASSIST_STRUCTURE, mCallingUid, mSessionComponentName.getPackageName()) == AppOpsManager.MODE_ALLOWED && structureEnabled) {
mAssistData.clear();
final int count = activityToken != null ? 1 : topActivities.size();
// Temp workaround for bug: 28348867 Revert after DP3
for (int i = 0; i < count && i < 1; i++) {
IBinder topActivity = count == 1 ? activityToken : topActivities.get(i);
try {
MetricsLogger.count(mContext, "assist_with_context", 1);
Bundle receiverExtras = new Bundle();
receiverExtras.putInt(KEY_RECEIVER_EXTRA_INDEX, i);
receiverExtras.putInt(KEY_RECEIVER_EXTRA_COUNT, count);
if (mAm.requestAssistContextExtras(ActivityManager.ASSIST_CONTEXT_FULL, mAssistReceiver, receiverExtras, topActivity, /* focused= */
i == 0, /* newSessionId= */
i == 0)) {
needDisclosure = true;
mPendingAssistDataCount++;
} else if (i == 0) {
// Wasn't allowed... given that, let's not do the screenshot either.
mHaveAssistData = true;
mAssistData.clear();
screenshotEnabled = false;
break;
}
} catch (RemoteException e) {
}
}
} else {
mHaveAssistData = true;
mAssistData.clear();
}
} else {
mAssistData.clear();
}
mHaveScreenshot = false;
if ((flags & VoiceInteractionSession.SHOW_WITH_SCREENSHOT) != 0) {
if (mAppOps.noteOpNoThrow(AppOpsManager.OP_ASSIST_SCREENSHOT, mCallingUid, mSessionComponentName.getPackageName()) == AppOpsManager.MODE_ALLOWED && screenshotEnabled) {
try {
MetricsLogger.count(mContext, "assist_with_screen", 1);
needDisclosure = true;
mIWindowManager.requestAssistScreenshot(mScreenshotReceiver);
} catch (RemoteException e) {
}
} else {
mHaveScreenshot = true;
mScreenshot = null;
}
} else {
mScreenshot = null;
}
if (needDisclosure && AssistUtils.shouldDisclose(mContext, mSessionComponentName)) {
mHandler.post(mShowAssistDisclosureRunnable);
}
if (mSession != null) {
try {
mSession.show(mShowArgs, mShowFlags, showCallback);
mShowArgs = null;
mShowFlags = 0;
} catch (RemoteException e) {
}
deliverSessionDataLocked();
} else if (showCallback != null) {
mPendingShowCallbacks.add(showCallback);
}
mCallback.onSessionShown(this);
return true;
}
if (showCallback != null) {
try {
showCallback.onFailed();
} catch (RemoteException e) {
}
}
return false;
}
use of android.os.UserHandle in project android_frameworks_base by DirtyUnicorns.
the class CallerInfoAsyncQuery method getCurrentProfileContentResolver.
/**
* @return {@link ContentResolver} for the "current" user.
*/
static ContentResolver getCurrentProfileContentResolver(Context context) {
if (DBG)
Rlog.d(LOG_TAG, "Trying to get current content resolver...");
final int currentUser = ActivityManager.getCurrentUser();
final int myUser = UserManager.get(context).getUserHandle();
if (DBG)
Rlog.d(LOG_TAG, "myUser=" + myUser + "currentUser=" + currentUser);
if (myUser != currentUser) {
final Context otherContext;
try {
otherContext = context.createPackageContextAsUser(context.getPackageName(), /* flags =*/
0, new UserHandle(currentUser));
return otherContext.getContentResolver();
} catch (NameNotFoundException e) {
Rlog.e(LOG_TAG, "Can't find self package", e);
// Fall back to the primary user.
}
}
return context.getContentResolver();
}
use of android.os.UserHandle in project android_frameworks_base by DirtyUnicorns.
the class ActivityTestMain method onCreateOptionsMenu.
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add("Animate!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AlertDialog.Builder builder = new AlertDialog.Builder(ActivityTestMain.this, R.style.SlowDialog);
builder.setTitle("This is a title");
builder.show();
return true;
}
});
menu.add("Bind!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
Intent intent = new Intent(ActivityTestMain.this, SingleUserService.class);
ServiceConnection conn = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
Log.i(TAG, "Service connected " + name + " " + service);
}
@Override
public void onServiceDisconnected(ComponentName name) {
Log.i(TAG, "Service disconnected " + name);
}
};
if (bindService(intent, conn, Context.BIND_AUTO_CREATE)) {
mConnections.add(conn);
} else {
Toast.makeText(ActivityTestMain.this, "Failed to bind", Toast.LENGTH_LONG).show();
}
return true;
}
});
menu.add("Start!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
Intent intent = new Intent(ActivityTestMain.this, SingleUserService.class);
startService(intent);
return true;
}
});
menu.add("Rebind Isolated!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
Intent intent = new Intent(ActivityTestMain.this, IsolatedService.class);
ServiceConnection conn = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
Log.i(TAG, "Isolated service connected " + name + " " + service);
}
@Override
public void onServiceDisconnected(ComponentName name) {
Log.i(TAG, "Isolated service disconnected " + name);
}
};
if (mIsolatedConnection != null) {
Log.i(TAG, "Unbinding existing service: " + mIsolatedConnection);
unbindService(mIsolatedConnection);
mIsolatedConnection = null;
}
Log.i(TAG, "Binding new service: " + conn);
if (bindService(intent, conn, Context.BIND_AUTO_CREATE)) {
mIsolatedConnection = conn;
} else {
Toast.makeText(ActivityTestMain.this, "Failed to bind", Toast.LENGTH_LONG).show();
}
return true;
}
});
menu.add("Send!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
Intent intent = new Intent(ActivityTestMain.this, SingleUserReceiver.class);
sendOrderedBroadcast(intent, null, new BroadcastResultReceiver(), null, Activity.RESULT_OK, null, null);
return true;
}
});
menu.add("Call!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
ContentProviderClient cpl = getContentResolver().acquireContentProviderClient(SingleUserProvider.AUTHORITY);
Bundle res = null;
try {
res = cpl.call("getuser", null, null);
} catch (RemoteException e) {
}
int user = res != null ? res.getInt("user", -1) : -1;
Toast.makeText(ActivityTestMain.this, "Provider executed as user " + (user >= 0 ? Integer.toString(user) : "unknown"), Toast.LENGTH_LONG).show();
cpl.release();
return true;
}
});
menu.add("Send to user 0!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
Intent intent = new Intent(ActivityTestMain.this, UserTarget.class);
sendOrderedBroadcastAsUser(intent, new UserHandle(0), null, new BroadcastResultReceiver(), null, Activity.RESULT_OK, null, null);
return true;
}
});
menu.add("Send to user " + mSecondUser + "!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
Intent intent = new Intent(ActivityTestMain.this, UserTarget.class);
sendOrderedBroadcastAsUser(intent, new UserHandle(mSecondUser), null, new BroadcastResultReceiver(), null, Activity.RESULT_OK, null, null);
return true;
}
});
menu.add("Bind to user 0!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
Intent intent = new Intent(ActivityTestMain.this, ServiceUserTarget.class);
ServiceConnection conn = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
Log.i(TAG, "Service connected " + name + " " + service);
}
@Override
public void onServiceDisconnected(ComponentName name) {
Log.i(TAG, "Service disconnected " + name);
}
};
if (bindServiceAsUser(intent, conn, Context.BIND_AUTO_CREATE, UserHandle.SYSTEM)) {
mConnections.add(conn);
} else {
Toast.makeText(ActivityTestMain.this, "Failed to bind", Toast.LENGTH_LONG).show();
}
return true;
}
});
menu.add("Bind to user " + mSecondUser + "!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
Intent intent = new Intent(ActivityTestMain.this, ServiceUserTarget.class);
ServiceConnection conn = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
Log.i(TAG, "Service connected " + name + " " + service);
}
@Override
public void onServiceDisconnected(ComponentName name) {
Log.i(TAG, "Service disconnected " + name);
}
};
if (bindServiceAsUser(intent, conn, Context.BIND_AUTO_CREATE, new UserHandle(mSecondUser))) {
mConnections.add(conn);
} else {
Toast.makeText(ActivityTestMain.this, "Failed to bind", Toast.LENGTH_LONG).show();
}
return true;
}
});
menu.add("Density!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
if (mOverrideConfig == null) {
mOverrideConfig = new Configuration();
}
if (mOverrideConfig.densityDpi == Configuration.DENSITY_DPI_UNDEFINED) {
mOverrideConfig.densityDpi = (getApplicationContext().getResources().getConfiguration().densityDpi * 2) / 3;
} else {
mOverrideConfig.densityDpi = Configuration.DENSITY_DPI_UNDEFINED;
}
recreate();
return true;
}
});
menu.add("HashArray").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
ArrayMapTests.run();
return true;
}
});
menu.add("Add App Recent").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
addAppRecents(1);
return true;
}
});
menu.add("Add App 10x Recent").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
addAppRecents(10);
return true;
}
});
menu.add("Exclude!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
setExclude(true);
return true;
}
});
menu.add("Include!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
setExclude(false);
return true;
}
});
menu.add("Open Doc").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
ActivityManager.AppTask task = findDocTask();
if (task == null) {
Intent intent = new Intent(ActivityTestMain.this, DocActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT | Intent.FLAG_ACTIVITY_MULTIPLE_TASK | Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS);
startActivity(intent);
} else {
task.moveToFront();
}
return true;
}
});
menu.add("Stack Doc").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
ActivityManager.AppTask task = findDocTask();
if (task != null) {
ActivityManager.RecentTaskInfo recent = task.getTaskInfo();
Intent intent = new Intent(ActivityTestMain.this, DocActivity.class);
if (recent.id >= 0) {
// Stack on top.
intent.putExtra(DocActivity.LABEL, "Stacked");
} else {
// Start root activity.
intent.putExtra(DocActivity.LABEL, "New Root");
}
task.startActivity(ActivityTestMain.this, intent, null);
}
return true;
}
});
menu.add("Spam!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
scheduleSpam(false);
return true;
}
});
menu.add("Track time").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "We are sharing this with you!");
ActivityOptions options = ActivityOptions.makeBasic();
Intent receiveIntent = new Intent(ActivityTestMain.this, TrackTimeReceiver.class);
receiveIntent.putExtra("something", "yeah, this is us!");
options.requestUsageTimeReport(PendingIntent.getBroadcast(ActivityTestMain.this, 0, receiveIntent, PendingIntent.FLAG_CANCEL_CURRENT));
startActivity(Intent.createChooser(intent, "Who do you love?"), options.toBundle());
return true;
}
});
menu.add("Transaction fail").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.putExtra("gulp", new int[1024 * 1024]);
startActivity(intent);
return true;
}
});
menu.add("Spam idle alarm").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
scheduleSpamAlarm(0);
return true;
}
});
menu.add("Ignore battery optimizations").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
Intent intent;
if (!mPower.isIgnoringBatteryOptimizations(getPackageName())) {
intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
intent.setData(Uri.fromParts("package", getPackageName(), null));
} else {
intent = new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
}
startActivity(intent);
return true;
}
});
return true;
}
use of android.os.UserHandle in project android_frameworks_base by DirtyUnicorns.
the class TileServices method getTileWrapper.
public TileServiceManager getTileWrapper(CustomTile tile) {
ComponentName component = tile.getComponent();
TileServiceManager service = onCreateTileService(component, tile.getQsTile());
synchronized (mServices) {
mServices.put(tile, service);
mTiles.put(component, tile);
mTokenMap.put(service.getToken(), tile);
// initialize package uninstall listener
String pkgName = component.getPackageName();
if (!mPkgListeners.containsKey(pkgName)) {
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
filter.addDataScheme("package");
PackageUninstallListener listener = new PackageUninstallListener(pkgName);
getContext().registerReceiverAsUser(listener, new UserHandle(ActivityManager.getCurrentUser()), filter, null, mHandler);
mPkgListeners.put(pkgName, listener);
}
mPkgListeners.get(pkgName).addComponent(component);
}
return service;
}
Aggregations