Java Code Examples for android.content.Context#startServiceAsUser()
The following examples show how to use
android.content.Context#startServiceAsUser() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CommonUtils.java From product-emm with Apache License 2.0 | 6 votes |
/** * Call EMM agent app to send operation updates. * @param context - Application context. * @param operation - Operation code. * @param operationId - Operation ID. * @param message - Error message. */ public static void callAgentApp(Context context, String operation, int operationId, String message) { Intent intent = new Intent(Constants.AGENT_APP_SERVICE_NAME); Intent explicitIntent = createExplicitFromImplicitIntent(context, intent); if (explicitIntent != null) { intent = explicitIntent; } intent.putExtra("operation", operation); if (operationId != 0) { intent.putExtra("id", operationId); } if (message != null) { intent.putExtra("message", message); } intent.setPackage(Constants.PACKAGE_NAME); context.startServiceAsUser(intent, android.os.Process.myUserHandle()); }
Example 2
Source File: NetworkConnectedReceiver.java From product-emm with Apache License 2.0 | 6 votes |
@Override public void onReceive(Context context, Intent intent) { Log.i(TAG, "Network change event triggered."); if(!Preference.getBoolean(context, FRESH_BOOTUP_FLAG)) { if (!Preference.getBoolean(context, Constants.PreferenceFlag.REGISTERED) && CommonUtils. isNetworkAvailable(context)) { if (Constants.AUTO_ENROLLMENT_BACKGROUND_SERVICE_ENABLED) { Preference.putBoolean(context, FRESH_BOOTUP_FLAG, true); Intent autoEnrollIntent = new Intent(context, EnrollmentService.class); autoEnrollIntent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); autoEnrollIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startServiceAsUser(autoEnrollIntent, android.os.Process.myUserHandle()); } CommonUtils.callSystemAppInit(context); } } }
Example 3
Source File: SystemServer.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
static final void startSystemUi(Context context, WindowManagerService windowManager) { Intent intent = new Intent(); intent.setComponent(new ComponentName("com.android.systemui", "com.android.systemui.SystemUIService")); intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING); //Slog.d(TAG, "Starting service: " + intent); context.startServiceAsUser(intent, UserHandle.SYSTEM); windowManager.onSystemUiStarted(); }
Example 4
Source File: CommonUtils.java From product-emm with Apache License 2.0 | 5 votes |
public static void callSystemAppInit(Context context) { if(Constants.SYSTEM_APP_ENABLED) { Intent intent = new Intent(Constants.SYSTEM_APP_SERVICE_START_ACTION); Intent explicitIntent = createExplicitFromImplicitIntent(context, intent); if (explicitIntent != null) { intent = explicitIntent; } context.startServiceAsUser(intent, android.os.Process.myUserHandle()); } else { Log.e(TAG, "System app not enabled."); } }
Example 5
Source File: CommonUtils.java From product-emm with Apache License 2.0 | 4 votes |
/** * Call EMM system app in COPE mode. * @param context - Application context. * @param operation - Operation code. * @param command - Shell command to be executed. * @param appUri - App package/APK URI when an app operation executed. */ public static void callSystemApp(Context context, String operation, String command, String appUri) { if(Constants.SYSTEM_APP_ENABLED) { Intent intent = new Intent(Constants.SYSTEM_APP_SERVICE_START_ACTION); Intent explicitIntent = createExplicitFromImplicitIntent(context, intent); if (explicitIntent != null) { intent = explicitIntent; } intent.putExtra(Constants.OPERATION_CODE, operation); intent.setPackage(Constants.PACKAGE_NAME); if (appUri != null) { intent.putExtra("appUri", appUri); } if (command != null) { if (Constants.Operation.UPGRADE_FIRMWARE.equals(operation)) { try { JSONObject upgradeData = new JSONObject(command); if (upgradeData.isNull(context.getResources() .getString(R.string.firmware_upgrade_automatic_retry)) && Preference.hasPreferenceKey(context, context .getResources().getString(R.string.is_automatic_firmware_upgrade))) { boolean isFirmwareUpgradeAutoRetry = Preference.getBoolean(context, context .getResources().getString(R.string.is_automatic_firmware_upgrade)); upgradeData.put(context.getResources() .getString(R.string.firmware_upgrade_automatic_retry), isFirmwareUpgradeAutoRetry); command = upgradeData.toString(); Log.d(TAG, "Updated payload: " + command); } else if (!upgradeData.isNull(context.getResources() .getString(R.string.firmware_upgrade_automatic_retry))){ Preference.putBoolean(context, context.getResources() .getString(R.string.is_automatic_firmware_upgrade), upgradeData.getBoolean(context.getResources() .getString(R.string.firmware_upgrade_automatic_retry))); } else { upgradeData.put(context.getResources() .getString(R.string.firmware_upgrade_automatic_retry), true); Preference.putBoolean(context, context.getResources() .getString(R.string.is_automatic_firmware_upgrade), true); Log.d(TAG, "Updated payload: " + command); } } catch (JSONException e) { Log.e(TAG, "Could not parse Firmware upgrade operation", e); } intent.putExtra("operationId", Preference.getInt(context, "firmwareOperationId")); } intent.putExtra("command", command); } context.startServiceAsUser(intent, android.os.Process.myUserHandle()); } else { Log.e(TAG, "System app not enabled."); } }