android.os.PersistableBundle Java Examples
The following examples show how to use
android.os.PersistableBundle.
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: PersistableBundleBuilder.java From your-local-weather with GNU General Public License v3.0 | 6 votes |
public static PersistableBundle fromAddress(android.location.Address address) { if (address == null) { return null; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { PersistableBundle persistableBundle = new PersistableBundle(); persistableBundle.putString("country", address.getLocale().getCountry()); persistableBundle.putString("language", address.getLocale().getLanguage()); persistableBundle.putString("variant", address.getLocale().getVariant()); persistableBundle.putString("locality", address.getLocality()); persistableBundle.putString("subLocality", address.getSubLocality()); persistableBundle.putString("adminArea", address.getAdminArea()); persistableBundle.putString("subAdminArea", address.getSubAdminArea()); persistableBundle.putString("countryName", address.getCountryName()); return persistableBundle; } else { return null; } }
Example #2
Source File: Support.java From FreezeYou with Apache License 2.0 | 6 votes |
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) static public boolean checkAndRequestIslandPermission(Context context) { final String TYPE_DELEGATION = "com.oasisfeng.island.delegation"; final String DELEGATION_APP_OPS = "-island-delegation-app-ops"; final String DELEGATION_PACKAGE_ACCESS = "delegation-package-access"; final RestrictionsManager rm = (RestrictionsManager) context.getSystemService(Context.RESTRICTIONS_SERVICE); if (rm != null && rm.hasRestrictionsProvider()) { // Otherwise, current user is not managed by Island or the version of Island is too low. final String[] delegations = rm.getApplicationRestrictions().getStringArray(TYPE_DELEGATION); if (delegations == null || !Arrays.asList(delegations).contains(DELEGATION_PACKAGE_ACCESS)) { final PersistableBundle request = new PersistableBundle(); request.putString(RestrictionsManager.REQUEST_KEY_DATA, DELEGATION_PACKAGE_ACCESS); rm.requestPermission(TYPE_DELEGATION, "cf.playhi.freezeyou.android.app-ops", request); } else { return true; } } return false; }
Example #3
Source File: BundleUtil.java From android-testdpc with Apache License 2.0 | 6 votes |
@TargetApi(VERSION_CODES.LOLLIPOP_MR1) public static Bundle persistableBundleToBundle(PersistableBundle persistableBundle) { Set<String> keySet = persistableBundle.keySet(); Bundle bundle = new Bundle(); for (String key : keySet) { Object value = persistableBundle.get(key); if (value instanceof Boolean) { bundle.putBoolean(key, (boolean) value); } else if (value instanceof Integer) { bundle.putInt(key, (int) value); } else if (value instanceof String) { bundle.putString(key, (String) value); } else if (value instanceof String[]) { bundle.putStringArray(key, (String[]) value); } else if (value instanceof PersistableBundle) { Bundle innerBundle = persistableBundleToBundle((PersistableBundle) value); bundle.putBundle(key, innerBundle); } } return bundle; }
Example #4
Source File: AddWatchNextService.java From leanback-homescreen-channels with Apache License 2.0 | 6 votes |
public static void scheduleAddWatchNextRequest(Context context, ClipData clipData) { JobScheduler scheduler = (JobScheduler) context.getSystemService(JOB_SCHEDULER_SERVICE); PersistableBundle bundle = new PersistableBundle(); bundle.putString(ID_KEY, clipData.getClipId()); bundle.putString(CONTENT_ID_KEY, clipData.getContentId()); bundle.putLong(DURATION_KEY, clipData.getDuration()); bundle.putLong(PROGRESS_KEY, clipData.getProgress()); bundle.putString(TITLE_KEY, clipData.getTitle()); bundle.putString(DESCRIPTION_KEY, clipData.getDescription()); bundle.putString(CARD_IMAGE_URL_KEY, clipData.getCardImageUrl()); scheduler.schedule(new JobInfo.Builder(1, new ComponentName(context, AddWatchNextService.class)) .setExtras(bundle) .build()); }
Example #5
Source File: SystemUpdateManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override public void updateSystemUpdateInfo(PersistableBundle infoBundle) { mContext.enforceCallingOrSelfPermission(Manifest.permission.RECOVERY, TAG); int status = infoBundle.getInt(KEY_STATUS, STATUS_UNKNOWN); if (status == STATUS_UNKNOWN) { Slog.w(TAG, "Invalid status info. Ignored"); return; } // There could be multiple updater apps running on a device. But only one at most should // be active (i.e. with a pending update), with the rest reporting idle status. We will // only accept the reported status if any of the following conditions holds: // a) none has been reported before; // b) the current on-file status was last reported by the same caller; // c) an active update is being reported. int uid = Binder.getCallingUid(); if (mLastUid == UID_UNKNOWN || mLastUid == uid || status != STATUS_IDLE) { synchronized (mLock) { saveSystemUpdateInfoLocked(infoBundle, uid); } } else { Slog.i(TAG, "Inactive updater reporting IDLE status. Ignored"); } }
Example #6
Source File: EpgSyncJobService.java From xipl with Apache License 2.0 | 6 votes |
/** * Initializes a job that will periodically update the app's channels and programs. * * @param context Application's context. * @param inputId Component name for the app's TvInputService. This can be received through an * Intent extra parameter {@link TvInputInfo#EXTRA_INPUT_ID}. * @param jobServiceComponent The {@link EpgSyncJobService} component name that will run. * @param fullSyncPeriod The period between when the job will run a full background sync in * milliseconds. * @param syncDuration The duration of EPG content to fetch in milliseconds. For a manual sync, * this should be relatively short. For a background sync this should be long. */ public static void setUpPeriodicSync( Context context, String inputId, ComponentName jobServiceComponent, long fullSyncPeriod, long syncDuration) { if (jobServiceComponent.getClass().isAssignableFrom(EpgSyncJobService.class)) { throw new IllegalArgumentException("This class does not extend EpgSyncJobService"); } PersistableBundle persistableBundle = new PersistableBundle(); persistableBundle.putString(EpgSyncJobService.BUNDLE_KEY_INPUT_ID, inputId); persistableBundle.putLong(EpgSyncJobService.BUNDLE_KEY_SYNC_PERIOD, syncDuration); JobInfo.Builder builder = new JobInfo.Builder(PERIODIC_SYNC_JOB_ID, jobServiceComponent); JobInfo jobInfo = builder.setExtras(persistableBundle) .setPeriodic(fullSyncPeriod) .setPersisted(true) .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY) .build(); scheduleJob(context, jobInfo); if (DEBUG) { Log.d(TAG, "Job has been scheduled for every " + fullSyncPeriod + "ms"); } }
Example #7
Source File: AppShortcutsModule.java From react-native-quick-actions with MIT License | 6 votes |
private void sendJSEvent(Intent intent) { if (!ACTION_SHORTCUT.equals(intent.getAction()) || !isShortcutSupported()) { return; } ShortcutItem item = null; PersistableBundle bundle = intent.getParcelableExtra(SHORTCUT_ITEM); if (bundle != null) { item = ShortcutItem.fromPersistableBundle(bundle); } if (item != null) { getReactApplicationContext() .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) .emit("quickActionShortcut", item.toWritableMap()); } }
Example #8
Source File: AppShortcutsModule.java From react-native-quick-actions with MIT License | 6 votes |
@ReactMethod @TargetApi(25) public void popInitialAction(Promise promise) { try { Activity currentActivity = getCurrentActivity(); WritableMap map = null; if (currentActivity != null) { Intent intent = currentActivity.getIntent(); if (ACTION_SHORTCUT.equals(intent.getAction())) { PersistableBundle bundle = intent.getParcelableExtra(SHORTCUT_ITEM); if (bundle != null) { ShortcutItem item = ShortcutItem.fromPersistableBundle(bundle); map = item.toWritableMap(); } } } promise.resolve(map); } catch (Exception e) { promise.reject(new JSApplicationIllegalArgumentException( "AppShortcuts.popInitialAction error. " + e.getMessage())); } }
Example #9
Source File: SetTrustAgentConfigFragment.java From android-testdpc with Apache License 2.0 | 6 votes |
private void showEditDialog(final String key) { mEditingKey = key; int type = KeyValuePairDialogFragment.DialogType.BOOL_TYPE; Object value = null; if (key != null) { value = mBundle.get(key); if (value instanceof Boolean) { type = KeyValuePairDialogFragment.DialogType.BOOL_TYPE; } else if (value instanceof Integer) { type = KeyValuePairDialogFragment.DialogType.INT_TYPE; } else if (value instanceof String) { type = KeyValuePairDialogFragment.DialogType.STRING_TYPE; } else if (value instanceof String[]) { type = KeyValuePairDialogFragment.DialogType.STRING_ARRAY_TYPE; } else if (value instanceof PersistableBundle) { type = KeyValuePairDialogFragment.DialogType.BUNDLE_TYPE; value = BundleUtil.persistableBundleToBundle((PersistableBundle) value); } } KeyValuePairDialogFragment dialogFragment = KeyValuePairDialogFragment.newInstance(type, true, key, value, SUPPORTED_TYPE, mResolveInfo.loadLabel(mPackageManager).toString()); dialogFragment.setTargetFragment(this, RESULT_CODE_EDIT_DIALOG); dialogFragment.show(getFragmentManager(), "dialog"); }
Example #10
Source File: EpgSyncJobService.java From xipl with Apache License 2.0 | 6 votes |
/** * Manually requests a job to run now. * * <p>To check the current status of the sync, register a {@link * android.content.BroadcastReceiver} with an {@link android.content.IntentFilter} which checks * for the action {@link #ACTION_SYNC_STATUS_CHANGED}. * * <p>The sync status is an extra parameter in the {@link Intent} with key {@link #SYNC_STATUS}. * The sync status is either {@link #SYNC_STARTED} or {@link #SYNC_FINISHED}. * * <p>Check that the value of {@link #BUNDLE_KEY_INPUT_ID} matches your {@link * android.media.tv.TvInputService}. If you're calling this from your setup activity, you can * get the extra parameter {@link TvInputInfo#EXTRA_INPUT_ID}. * * <p> * * @param context Application's context. * @param inputId Component name for the app's TvInputService. This can be received through an * Intent extra parameter {@link TvInputInfo#EXTRA_INPUT_ID}. * @param syncDuration The duration of EPG content to fetch in milliseconds. For a manual sync, * this should be relatively short. For a background sync this should be long. * @param jobServiceComponent The {@link EpgSyncJobService} class that will run. */ public static void requestImmediateSync( Context context, String inputId, long syncDuration, ComponentName jobServiceComponent) { if (jobServiceComponent.getClass().isAssignableFrom(EpgSyncJobService.class)) { throw new IllegalArgumentException("This class does not extend EpgSyncJobService"); } PersistableBundle persistableBundle = new PersistableBundle(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { persistableBundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); persistableBundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true); } persistableBundle.putString(EpgSyncJobService.BUNDLE_KEY_INPUT_ID, inputId); persistableBundle.putLong(EpgSyncJobService.BUNDLE_KEY_SYNC_PERIOD, syncDuration); JobInfo.Builder builder = new JobInfo.Builder(REQUEST_SYNC_JOB_ID, jobServiceComponent); JobInfo jobInfo = builder.setExtras(persistableBundle) .setOverrideDeadline(EpgSyncJobService.OVERRIDE_DEADLINE_MILLIS) .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY) .build(); scheduleJob(context, jobInfo); if (DEBUG) { Log.d(TAG, "Single job scheduled"); } }
Example #11
Source File: PersistableBundleCompat.java From JobSchedulerCompat with Apache License 2.0 | 5 votes |
static Object get(Object bundle, String key) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { return ((PersistableBundle) bundle).get(key); } else { return ((Bundle) bundle).get(key); } }
Example #12
Source File: PersistableBundleCompat.java From JobSchedulerCompat with Apache License 2.0 | 5 votes |
static void putAll(Object bundle, Object allBundle) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { ((PersistableBundle) bundle).putAll((PersistableBundle) allBundle); } else { ((Bundle) bundle).putAll((Bundle) allBundle); } }
Example #13
Source File: GnssLocationProvider.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private void subscriptionOrSimChanged(Context context) { if (DEBUG) Log.d(TAG, "received SIM related action: "); TelephonyManager phone = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); CarrierConfigManager configManager = (CarrierConfigManager) mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE); String mccMnc = phone.getSimOperator(); boolean isKeepLppProfile = false; if (!TextUtils.isEmpty(mccMnc)) { if (DEBUG) Log.d(TAG, "SIM MCC/MNC is available: " + mccMnc); synchronized (mLock) { if (configManager != null) { PersistableBundle b = configManager.getConfig(); if (b != null) { isKeepLppProfile = b.getBoolean(CarrierConfigManager.KEY_PERSIST_LPP_MODE_BOOL); } } if (isKeepLppProfile) { // load current properties for the carrier loadPropertiesFromResource(context, mProperties); String lpp_profile = mProperties.getProperty("LPP_PROFILE"); // set the persist property LPP_PROFILE for the value if (lpp_profile != null) { SystemProperties.set(LPP_PROFILE, lpp_profile); } } else { // reset the persist property SystemProperties.set(LPP_PROFILE, ""); } reloadGpsProperties(context, mProperties); mNIHandler.setSuplEsEnabled(mSuplEsEnabled); } } else { if (DEBUG) Log.d(TAG, "SIM MCC/MNC is still not available"); } }
Example #14
Source File: ShortcutService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
static void writeTagExtra(XmlSerializer out, String tag, PersistableBundle bundle) throws IOException, XmlPullParserException { if (bundle == null) return; out.startTag(null, tag); bundle.saveToXml(out); out.endTag(null, tag); }
Example #15
Source File: PersistableBundleCompat.java From JobSchedulerCompat with Apache License 2.0 | 5 votes |
static String[] getStringArray(Object bundle, String key) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { return ((PersistableBundle) bundle).getStringArray(key); } else { return ((Bundle) bundle).getStringArray(key); } }
Example #16
Source File: UserManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Override public PersistableBundle getSeedAccountOptions() throws RemoteException { checkManageUsersPermission("Cannot get seed account information"); synchronized (mUsersLock) { UserData userData = getUserDataLU(UserHandle.getCallingUserId()); return userData.seedAccountOptions; } }
Example #17
Source File: SetupManagementFragment.java From android-testdpc with Apache License 2.0 | 5 votes |
private void maybePassAffiliationIds(Intent intent, PersistableBundle adminExtras) { if (Util.isDeviceOwner(getActivity()) && ACTION_PROVISION_MANAGED_PROFILE.equals(intent.getAction()) && Util.SDK_INT >= VERSION_CODES.O) { passAffiliationIds(intent, adminExtras); } }
Example #18
Source File: SystemUpdateManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Nullable private PersistableBundle readInfoFileLocked(XmlPullParser parser) throws XmlPullParserException, IOException { int type; while ((type = parser.next()) != END_DOCUMENT) { if (type == START_TAG && TAG_INFO.equals(parser.getName())) { return PersistableBundle.restoreFromXml(parser); } } return null; }
Example #19
Source File: OtherBillBookActivity.java From NovelReader with MIT License | 5 votes |
/***************************************************/ @Override public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) { super.onSaveInstanceState(outState, outPersistentState); outState.putString(EXTRA_BILL_ID,mBillId); outState.putString(EXTRA_BILL_NAME,mBillName); }
Example #20
Source File: RestrictionsReceiver.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Intercept standard Restrictions Provider broadcasts. Implementations * should not override this method; it is better to implement the * convenience callbacks for each action. */ @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (RestrictionsManager.ACTION_REQUEST_PERMISSION.equals(action)) { String packageName = intent.getStringExtra(RestrictionsManager.EXTRA_PACKAGE_NAME); String requestType = intent.getStringExtra(RestrictionsManager.EXTRA_REQUEST_TYPE); String requestId = intent.getStringExtra(RestrictionsManager.EXTRA_REQUEST_ID); PersistableBundle request = (PersistableBundle) intent.getParcelableExtra(RestrictionsManager.EXTRA_REQUEST_BUNDLE); onRequestPermission(context, packageName, requestType, requestId, request); } }
Example #21
Source File: Util.java From BackPackTrackII with GNU General Public License v3.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1) public static Bundle getBundle(PersistableBundle arg) { Bundle result = new Bundle(); for (String key : arg.keySet()) if (arg.get(key) instanceof Boolean) result.putBoolean(key, arg.getBoolean(key)); else if (arg.get(key) instanceof Integer) result.putInt(key, arg.getInt(key)); else if (arg.get(key) instanceof Long) result.putLong(key, arg.getLong(key)); else if (arg.get(key) instanceof String || arg.get(key) == null) result.putString(key, arg.getString(key)); return result; }
Example #22
Source File: DocumentCentricActivity.java From android-DocumentCentricApps with Apache License 2.0 | 5 votes |
@Override public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) { /* To maintain activity state across reboots the system saves and restore critical information for all tasks and their activities. Information known by the system includes the activity stack order, each task’s thumbnails and each activity’s and task's Intents. For Information that cannot be retained because they contain Bundles which can’t be persisted a new constrained version of Bundle, PersistableBundle is added. PersistableBundle can store only basic data types. To use it in your Activities you must declare the new activity:persistableMode attribute in the manifest. */ outPersistentState.putInt(KEY_EXTRA_NEW_DOCUMENT_COUNTER, mDocumentCounter); super.onSaveInstanceState(outState, outPersistentState); }
Example #23
Source File: FrameworkMediaDrm.java From MediaSDK with Apache License 2.0 | 5 votes |
@Override @Nullable @TargetApi(28) public PersistableBundle getMetrics() { if (Util.SDK_INT < 28) { return null; } return mediaDrm.getMetrics(); }
Example #24
Source File: ShortcutItem.java From react-native-quick-actions with MIT License | 5 votes |
static ShortcutItem fromPersistableBundle(PersistableBundle bundle) { final ShortcutItem item = new ShortcutItem(); item.type = bundle.getString("type"); item.title = bundle.getString("title"); item.icon = bundle.getString("icon"); item.userInfo = UserInfo.fromPersistableBundle(bundle.getPersistableBundle("userInfo")); return item; }
Example #25
Source File: PersistableBundleCompat.java From JobSchedulerCompat with Apache License 2.0 | 5 votes |
static void remove(Object bundle, String key) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { ((PersistableBundle) bundle).remove(key); } else { ((Bundle) bundle).remove(key); } }
Example #26
Source File: PostProvisioningTask.java From android-testdpc with Apache License 2.0 | 5 votes |
@TargetApi(VERSION_CODES.O) private void maybeSetAffiliationIds(PersistableBundle extras) { if (extras == null) { return; } String affiliationId = extras.getString(LaunchIntentUtil.EXTRA_AFFILIATION_ID); if (affiliationId != null) { mDevicePolicyManager.setAffiliationIds( getComponentName(mContext), Collections.singleton(affiliationId)); } }
Example #27
Source File: Util.java From BackPackTrackII with GNU General Public License v3.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1) public static PersistableBundle getPersistableBundle(Bundle bundle) { PersistableBundle result = new PersistableBundle(); for (String key : bundle.keySet()) if (bundle.get(key) instanceof Boolean) result.putBoolean(key, bundle.getBoolean(key)); else if (bundle.get(key) instanceof Integer) result.putInt(key, bundle.getInt(key)); else if (bundle.get(key) instanceof Long) result.putLong(key, bundle.getLong(key)); else if (bundle.get(key) instanceof String || bundle.get(key) == null) result.putString(key, bundle.getString(key)); return result; }
Example #28
Source File: PersistableBundleCompat.java From JobSchedulerCompat with Apache License 2.0 | 5 votes |
static boolean containsKey(Object bundle, String key) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { return ((PersistableBundle) bundle).containsKey(key); } else { return ((Bundle) bundle).containsKey(key); } }
Example #29
Source File: PersistableBundleCompat.java From JobSchedulerCompat with Apache License 2.0 | 5 votes |
static void putLong(Object bundle, String key, long value) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { ((PersistableBundle) bundle).putLong(key, value); } else { ((Bundle) bundle).putLong(key, value); } }
Example #30
Source File: DeleteWatchNextService.java From leanback-homescreen-channels with Apache License 2.0 | 5 votes |
public static void scheduleDeleteWatchNextRequest(Context context, String clipId) { JobScheduler scheduler = (JobScheduler) context.getSystemService(JOB_SCHEDULER_SERVICE); PersistableBundle bundle = new PersistableBundle(); bundle.putString(ID_KEY, clipId); scheduler.schedule(new JobInfo.Builder(1, new ComponentName(context, DeleteWatchNextService.class)) .setExtras(bundle) .build()); }