List of usage examples for android.os Process myUserHandle
public static UserHandle myUserHandle()
From source file:Main.java
/** * @see android.content.pm.PackageManager#getUserBadgedDrawableForDensity(Drawable drawable, * UserHandle user, Rect badgeLocation, int badgeDensity). *//*from www .j av a2s . c om*/ public static Drawable getUserBadgedDrawableForDensity(Context context, Drawable drawable, Rect badgeLocation, int density) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { PackageManager packageManager = context.getPackageManager(); return packageManager.getUserBadgedDrawableForDensity(drawable, Process.myUserHandle(), badgeLocation, density); } return drawable; }
From source file:Main.java
/** * @see android.content.pm.PackageManager#getUserBadgedIcon(Drawable, android.os.UserHandle). *//*from w w w .j a va 2s. c om*/ public static Drawable getUserBadgedIcon(Context context, int id) { Drawable drawable = getDrawable(context.getResources(), id); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { PackageManager packageManager = context.getPackageManager(); drawable = packageManager.getUserBadgedIcon(drawable, Process.myUserHandle()); } return drawable; }
From source file:com.farmerbb.taskbar.receiver.ReceiveSettingsReceiver.java
@Override public void onReceive(Context context, Intent intent) { // Ignore this broadcast if this is the free version if (BuildConfig.APPLICATION_ID.equals(BuildConfig.PAID_APPLICATION_ID)) { // Get pinned and blocked apps PinnedBlockedApps pba = PinnedBlockedApps.getInstance(context); pba.clear(context);//from www .j av a 2s .c o m String[] pinnedAppsPackageNames = intent.getStringArrayExtra("pinned_apps_package_names"); String[] pinnedAppsComponentNames = intent.getStringArrayExtra("pinned_apps_component_names"); String[] pinnedAppsLabels = intent.getStringArrayExtra("pinned_apps_labels"); long[] pinnedAppsUserIds = intent.getLongArrayExtra("pinned_apps_user_ids"); UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE); LauncherApps launcherApps = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE); if (pinnedAppsPackageNames != null && pinnedAppsComponentNames != null && pinnedAppsLabels != null) for (int i = 0; i < pinnedAppsPackageNames.length; i++) { Intent throwaway = new Intent(); throwaway.setComponent(ComponentName.unflattenFromString(pinnedAppsComponentNames[i])); long userId; if (pinnedAppsUserIds != null) userId = pinnedAppsUserIds[i]; else userId = userManager.getSerialNumberForUser(Process.myUserHandle()); AppEntry newEntry = new AppEntry(pinnedAppsPackageNames[i], pinnedAppsComponentNames[i], pinnedAppsLabels[i], IconCache.getInstance(context).getIcon(context, context.getPackageManager(), launcherApps.resolveActivity(throwaway, userManager.getUserForSerialNumber(userId))), true); newEntry.setUserId(userId); pba.addPinnedApp(context, newEntry); } String[] blockedAppsPackageNames = intent.getStringArrayExtra("blocked_apps_package_names"); String[] blockedAppsComponentNames = intent.getStringArrayExtra("blocked_apps_component_names"); String[] blockedAppsLabels = intent.getStringArrayExtra("blocked_apps_labels"); if (blockedAppsPackageNames != null && blockedAppsComponentNames != null && blockedAppsLabels != null) for (int i = 0; i < blockedAppsPackageNames.length; i++) { pba.addBlockedApp(context, new AppEntry(blockedAppsPackageNames[i], blockedAppsComponentNames[i], blockedAppsLabels[i], null, false)); } // Get blacklist Blacklist blacklist = Blacklist.getInstance(context); blacklist.clear(context); String[] blacklistPackageNames = intent.getStringArrayExtra("blacklist_package_names"); String[] blacklistLabels = intent.getStringArrayExtra("blacklist_labels"); if (blacklistPackageNames != null && blacklistLabels != null) for (int i = 0; i < blacklistPackageNames.length; i++) { blacklist.addBlockedApp(context, new BlacklistEntry(blacklistPackageNames[i], blacklistLabels[i])); } // Get top apps TopApps topApps = TopApps.getInstance(context); topApps.clear(context); String[] topAppsPackageNames = intent.getStringArrayExtra("top_apps_package_names"); String[] topAppsLabels = intent.getStringArrayExtra("top_apps_labels"); if (topAppsPackageNames != null && topAppsLabels != null) for (int i = 0; i < topAppsPackageNames.length; i++) { topApps.addTopApp(context, new BlacklistEntry(topAppsPackageNames[i], topAppsLabels[i])); } // Get saved window sizes if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { SavedWindowSizes savedWindowSizes = SavedWindowSizes.getInstance(context); savedWindowSizes.clear(context); String[] savedWindowSizesComponentNames = intent .getStringArrayExtra("saved_window_sizes_component_names"); String[] savedWindowSizesWindowSizes = intent .getStringArrayExtra("saved_window_sizes_window_sizes"); if (savedWindowSizesComponentNames != null && savedWindowSizesWindowSizes != null) for (int i = 0; i < savedWindowSizesComponentNames.length; i++) { savedWindowSizes.setWindowSize(context, savedWindowSizesComponentNames[i], savedWindowSizesWindowSizes[i]); } } // Get shared preferences String contents = intent.getStringExtra("preferences"); if (contents.length() > 0) try { File file = new File(context.getFilesDir().getParent() + "/shared_prefs/" + BuildConfig.APPLICATION_ID + "_preferences.xml"); FileOutputStream output = new FileOutputStream(file); output.write(contents.getBytes()); output.close(); } catch (IOException e) { /* Gracefully fail */ } try { File file = new File(context.getFilesDir() + File.separator + "imported_successfully"); if (file.createNewFile()) LocalBroadcastManager.getInstance(context) .sendBroadcast(new Intent("com.farmerbb.taskbar.IMPORT_FINISHED")); } catch (IOException e) { /* Gracefully fail */ } } }
From source file:com.android.managedprovisioning.ProfileOwnerPreProvisioningActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final LayoutInflater inflater = getLayoutInflater(); View contentView = inflater.inflate(R.layout.user_consent, null); setContentView(contentView);//from www.ja v a2 s .c om // Check whether system has the required managed profile feature. if (!systemHasManagedProfileFeature()) { showErrorAndClose(R.string.managed_provisioning_not_supported, "Exiting managed profile provisioning, " + "managed profiles feature is not available"); return; } if (Process.myUserHandle().getIdentifier() != UserHandle.USER_OWNER) { showErrorAndClose(R.string.user_is_not_owner, "Exiting managed profile provisioning, calling user is not owner."); return; } // Initialize member variables from the intent, stop if the intent wasn't valid. try { initialize(getIntent()); } catch (ProvisioningFailedException e) { showErrorAndClose(R.string.managed_provisioning_error_text, e.getMessage()); return; } setMdmIcon(mMdmPackageName); // If the caller started us via ALIAS_NO_CHECK_CALLER then they must have permission to // MANAGE_USERS since it is a restricted intent. Otherwise, check the calling package. boolean hasManageUsersPermission = (getComponentName().equals(ALIAS_NO_CHECK_CALLER)); if (!hasManageUsersPermission) { // Calling package has to equal the requested device admin package or has to be system. String callingPackage = getCallingPackage(); if (callingPackage == null) { showErrorAndClose(R.string.managed_provisioning_error_text, "Calling package is null. " + "Was startActivityForResult used to start this activity?"); return; } if (!callingPackage.equals(mMdmPackageName) && !packageHasManageUsersPermission(callingPackage)) { showErrorAndClose(R.string.managed_provisioning_error_text, "Permission denied, " + "calling package tried to set a different package as profile owner. " + "The system MANAGE_USERS permission is required."); return; } } DevicePolicyManager dpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); String deviceOwner = dpm.getDeviceOwner(); if (deviceOwner != null && !deviceOwner.equals(mMdmPackageName)) { showErrorAndClose(R.string.managed_provisioning_error_text, "Permission denied, " + "profile owner must be in the same package as device owner."); return; } // If there is already a managed profile, allow the user to cancel or delete it. int existingManagedProfileUserId = alreadyHasManagedProfile(); if (existingManagedProfileUserId != -1) { showManagedProfileExistsDialog(existingManagedProfileUserId); } else { showStartProvisioningScreen(); } }
From source file:com.android.managedprovisioning.ProfileOwnerProvisioningService.java
/** * Called when the new profile or managed user is ready for provisioning (the profile is created * and all the apps not needed have been deleted). *//*from w ww .j a va 2 s . com*/ private void setUpUserOrProfile() throws ProvisioningException { installMdmOnManagedProfile(); setMdmAsActiveAdmin(); setMdmAsManagedProfileOwner(); if (!isProvisioningManagedUser()) { setOrganizationColor(); setDefaultUserRestrictions(); CrossProfileIntentFiltersHelper.setFilters(getPackageManager(), getUserId(), mManagedProfileOrUserInfo.id); if (!startManagedProfile(mManagedProfileOrUserInfo.id)) { throw raiseError("Could not start user in background"); } // Wait for ACTION_USER_UNLOCKED to be sent before trying to migrate the account. // Even if no account is present, we should not send the provisioning complete broadcast // before the managed profile user is properly started. if ((mUnlockedReceiver != null) && !mUnlockedReceiver.waitForUserUnlocked()) { return; } // Note: account migration must happen after setting the profile owner. // Otherwise, there will be a time interval where some apps may think that the account // does not have a profile owner. mUtils.maybeCopyAccount(this, mParams.accountToMigrate, Process.myUserHandle(), mManagedProfileOrUserInfo.getUserHandle()); } }
From source file:com.android.managedprovisioning.DeviceOwnerProvisioningService.java
private void maybeCopyAccount() { if (!UserManager.isSplitSystemUser()) { // Only one user involved in this case. return;/*from w w w .ja v a 2 s . c o m*/ } mUtils.maybeCopyAccount(DeviceOwnerProvisioningService.this, mParams.accountToMigrate, UserHandle.SYSTEM, Process.myUserHandle()); }
From source file:com.farmerbb.taskbar.service.DashboardService.java
private void cellClick(View view, boolean isActualClick) { Bundle bundle = (Bundle) view.getTag(); int cellId = bundle.getInt("cellId"); int appWidgetId = bundle.getInt("appWidgetId", -1); int currentlySelectedCell = appWidgetId == -1 ? cellId : -1; SharedPreferences pref = U.getSharedPreferences(this); boolean shouldShowPlaceholder = pref .getBoolean("dashboard_widget_" + Integer.toString(cellId) + "_placeholder", false); if (isActualClick && ((appWidgetId == -1 && currentlySelectedCell == previouslySelectedCell) || shouldShowPlaceholder)) { fadeOut(false);/*from ww w . j a v a 2 s .c o m*/ FrameLayout frameLayout = cells.get(currentlySelectedCell); frameLayout.findViewById(R.id.empty).setVisibility(View.GONE); Intent intent = new Intent("com.farmerbb.taskbar.ADD_WIDGET_REQUESTED"); intent.putExtra("appWidgetId", APPWIDGET_HOST_ID); intent.putExtra("cellId", cellId); LocalBroadcastManager.getInstance(DashboardService.this).sendBroadcast(intent); if (shouldShowPlaceholder) { String providerName = pref.getString("dashboard_widget_" + Integer.toString(cellId) + "_provider", "null"); if (!providerName.equals("null")) { ComponentName componentName = ComponentName.unflattenFromString(providerName); List<AppWidgetProviderInfo> providerInfoList = mAppWidgetManager .getInstalledProvidersForProfile(Process.myUserHandle()); for (AppWidgetProviderInfo info : providerInfoList) { if (info.provider.equals(componentName)) { U.showToast(this, getString(R.string.widget_restore_toast, info.loadLabel(getPackageManager())), Toast.LENGTH_SHORT); break; } } } } previouslySelectedCell = -1; } else { for (int i = 0; i < maxSize; i++) { FrameLayout frameLayout = cells.get(i); frameLayout.findViewById(R.id.empty).setVisibility( i == currentlySelectedCell && !shouldShowPlaceholder ? View.VISIBLE : View.GONE); } previouslySelectedCell = currentlySelectedCell; } }
From source file:com.android.managedprovisioning.ProfileOwnerProvisioningService.java
private void createProfile(String profileName) throws ProvisioningException { ProvisionLogger.logd("Creating managed profile with name " + profileName); mManagedProfileOrUserInfo = mUserManager.createProfileForUser(profileName, UserInfo.FLAG_MANAGED_PROFILE | UserInfo.FLAG_DISABLED, Process.myUserHandle().getIdentifier()); if (mManagedProfileOrUserInfo == null) { throw raiseError("Couldn't create profile."); }/* w w w . j ava 2 s . c o m*/ }
From source file:com.farmerbb.taskbar.service.DashboardService.java
private void addPlaceholder(int cellId) { FrameLayout placeholder = (FrameLayout) cells.get(cellId).findViewById(R.id.placeholder); SharedPreferences pref = U.getSharedPreferences(this); String providerName = pref.getString("dashboard_widget_" + Integer.toString(cellId) + "_provider", "null"); if (!providerName.equals("null")) { ImageView imageView = (ImageView) placeholder.findViewById(R.id.placeholder_image); ComponentName componentName = ComponentName.unflattenFromString(providerName); List<AppWidgetProviderInfo> providerInfoList = mAppWidgetManager .getInstalledProvidersForProfile(Process.myUserHandle()); for (AppWidgetProviderInfo info : providerInfoList) { if (info.provider.equals(componentName)) { Drawable drawable = info.loadPreviewImage(this, -1); if (drawable == null) drawable = info.loadIcon(this, -1); ColorMatrix matrix = new ColorMatrix(); matrix.setSaturation(0); imageView.setImageDrawable(drawable); imageView.setColorFilter(new ColorMatrixColorFilter(matrix)); break; }//from w ww .j av a 2 s . c om } } placeholder.setVisibility(View.VISIBLE); }