Java Code Examples for android.util.ArrayMap#values()
The following examples show how to use
android.util.ArrayMap#values() .
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: ResourcesLoader.java From buck with Apache License 2.0 | 6 votes |
@TargetApi(KITKAT) public List<LoadedApkInternal> getLoadedApks() throws NoSuchFieldException, IllegalAccessException { List<LoadedApkInternal> loadedApks = new ArrayList<>(); for (String field : new String[] {"mPackages", "mResourcePackages"}) { ArrayMap packages = (ArrayMap) Reflect.getField(activityThread, sActivityThreadClass, field); for (Object loadedApkRef : packages.values()) { Object loadedApk = ((WeakReference) loadedApkRef).get(); if (loadedApk == null) { continue; } loadedApks.add(new LoadedApkInternal(loadedApk)); } } return loadedApks; }
Example 2
Source File: DebugService.java From input-samples with Apache License 2.0 | 5 votes |
static FillResponse createResponse(@NonNull Context context, @NonNull ArrayMap<String, AutofillId> fields, int numDatasets, boolean authenticateDatasets) { String packageName = context.getPackageName(); FillResponse.Builder response = new FillResponse.Builder(); // 1.Add the dynamic datasets for (int i = 1; i <= numDatasets; i++) { Dataset unlockedDataset = newUnlockedDataset(fields, packageName, i); if (authenticateDatasets) { Dataset.Builder lockedDataset = new Dataset.Builder(); for (Entry<String, AutofillId> field : fields.entrySet()) { String hint = field.getKey(); AutofillId id = field.getValue(); String value = i + "-" + hint; IntentSender authentication = SimpleAuthActivity.newIntentSenderForDataset(context, unlockedDataset); RemoteViews presentation = newDatasetPresentation(packageName, "Tap to auth " + value); lockedDataset.setValue(id, null, presentation) .setAuthentication(authentication); } response.addDataset(lockedDataset.build()); } else { response.addDataset(unlockedDataset); } } // 2.Add save info Collection<AutofillId> ids = fields.values(); AutofillId[] requiredIds = new AutofillId[ids.size()]; ids.toArray(requiredIds); response.setSaveInfo( // We're simple, so we're generic new SaveInfo.Builder(SaveInfo.SAVE_DATA_TYPE_GENERIC, requiredIds).build()); // 3.Profit! return response.build(); }
Example 3
Source File: PermissionSettings.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Transfers ownership of permissions from one package to another. */ public void transferPermissions(String origPackageName, String newPackageName) { synchronized (mLock) { for (int i=0; i<2; i++) { ArrayMap<String, BasePermission> permissions = i == 0 ? mPermissionTrees : mPermissions; for (BasePermission bp : permissions.values()) { bp.transfer(origPackageName, newPackageName); } } } }
Example 4
Source File: ProxyUtil.java From CapturePacket with MIT License | 5 votes |
@TargetApi(Build.VERSION_CODES.KITKAT) private static boolean setProxyLollipop(final Context context, String host, int port) { System.setProperty("http.proxyHost", host); System.setProperty("http.proxyPort", port + ""); System.setProperty("https.proxyHost", host); System.setProperty("https.proxyPort", port + ""); try { Context appContext = context.getApplicationContext(); Class applictionClass = Class.forName("android.app.Application"); Field mLoadedApkField = applictionClass.getDeclaredField("mLoadedApk"); mLoadedApkField.setAccessible(true); Object mloadedApk = mLoadedApkField.get(appContext); Class loadedApkClass = Class.forName("android.app.LoadedApk"); Field mReceiversField = loadedApkClass.getDeclaredField("mReceivers"); mReceiversField.setAccessible(true); ArrayMap receivers = (ArrayMap) mReceiversField.get(mloadedApk); for (Object receiverMap : receivers.values()) { for (Object receiver : ((ArrayMap) receiverMap).keySet()) { Class clazz = receiver.getClass(); if (clazz.getName().contains("ProxyChangeListener")) { Method onReceiveMethod = clazz.getDeclaredMethod("onReceive", Context.class, Intent.class); Intent intent = new Intent(Proxy.PROXY_CHANGE_ACTION); onReceiveMethod.invoke(receiver, appContext, intent); } } } } catch (Exception e) { e.printStackTrace(); return false; } return true; }
Example 5
Source File: DebugService.java From android-AutofillFramework with Apache License 2.0 | 5 votes |
static FillResponse createResponse(@NonNull Context context, @NonNull ArrayMap<String, AutofillId> fields, int numDatasets, boolean authenticateDatasets) { String packageName = context.getPackageName(); FillResponse.Builder response = new FillResponse.Builder(); // 1.Add the dynamic datasets for (int i = 1; i <= numDatasets; i++) { Dataset unlockedDataset = newUnlockedDataset(fields, packageName, i); if (authenticateDatasets) { Dataset.Builder lockedDataset = new Dataset.Builder(); for (Entry<String, AutofillId> field : fields.entrySet()) { String hint = field.getKey(); AutofillId id = field.getValue(); String value = i + "-" + hint; IntentSender authentication = SimpleAuthActivity.newIntentSenderForDataset(context, unlockedDataset); RemoteViews presentation = newDatasetPresentation(packageName, "Tap to auth " + value); lockedDataset.setValue(id, null, presentation) .setAuthentication(authentication); } response.addDataset(lockedDataset.build()); } else { response.addDataset(unlockedDataset); } } // 2.Add save info Collection<AutofillId> ids = fields.values(); AutofillId[] requiredIds = new AutofillId[ids.size()]; ids.toArray(requiredIds); response.setSaveInfo( // We're simple, so we're generic new SaveInfo.Builder(SaveInfo.SAVE_DATA_TYPE_GENERIC, requiredIds).build()); // 3.Profit! return response.build(); }
Example 6
Source File: ProxyUtils.java From AndroidHttpCapture with MIT License | 5 votes |
@TargetApi(Build.VERSION_CODES.KITKAT) private static boolean setProxyLollipop(final Context context, String host, int port) { System.setProperty("http.proxyHost", host); System.setProperty("http.proxyPort", port + ""); System.setProperty("https.proxyHost", host); System.setProperty("https.proxyPort", port + ""); try { Context appContext = context.getApplicationContext(); Class applictionClass = Class.forName("android.app.Application"); Field mLoadedApkField = applictionClass.getDeclaredField("mLoadedApk"); mLoadedApkField.setAccessible(true); Object mloadedApk = mLoadedApkField.get(appContext); Class loadedApkClass = Class.forName("android.app.LoadedApk"); Field mReceiversField = loadedApkClass.getDeclaredField("mReceivers"); mReceiversField.setAccessible(true); ArrayMap receivers = (ArrayMap) mReceiversField.get(mloadedApk); for (Object receiverMap : receivers.values()) { for (Object receiver : ((ArrayMap) receiverMap).keySet()) { Class clazz = receiver.getClass(); if (clazz.getName().contains("ProxyChangeListener")) { Method onReceiveMethod = clazz.getDeclaredMethod("onReceive", Context.class, Intent.class); Intent intent = new Intent(Proxy.PROXY_CHANGE_ACTION); onReceiveMethod.invoke(receiver, appContext, intent); } } } } catch (Exception e) { e.printStackTrace(); return false; } return true; }
Example 7
Source File: Util.java From FTCVision with MIT License | 5 votes |
/** * Gets the primary activity without calling from an Activity class * * @return the main Activity */ @SuppressWarnings("unchecked") @TargetApi(Build.VERSION_CODES.KITKAT) public static Activity getActivity() { /*ActivityManager am = (ActivityManager)getContext().getSystemService(Context.ACTIVITY_SERVICE); ComponentName cn = am.getRunningTasks(1).get(0).topActivity;*/ try { Class activityThreadClass = Class.forName("android.app.ActivityThread"); Object activityThread = activityThreadClass.getMethod("currentActivityThread").invoke(null); Field activitiesField = activityThreadClass.getDeclaredField("mActivities"); activitiesField.setAccessible(true); ArrayMap activities = (ArrayMap) activitiesField.get(activityThread); for (Object activityRecord : activities.values()) { Class activityRecordClass = activityRecord.getClass(); Field pausedField = activityRecordClass.getDeclaredField("paused"); pausedField.setAccessible(true); if (!pausedField.getBoolean(activityRecord)) { Field activityField = activityRecordClass.getDeclaredField("activity"); activityField.setAccessible(true); return (Activity) activityField.get(activityRecord); } } } catch (final java.lang.Throwable e) { // handle exception throw new IllegalArgumentException("No activity could be retrieved!"); } throw new IllegalArgumentException("No activity could be found!"); }
Example 8
Source File: WebViewProxyUtil.java From FaceSlim with GNU General Public License v2.0 | 5 votes |
/** * Set Proxy for Android 5.0 and above. */ @SuppressWarnings("all") private static boolean setLollipopWebViewProxy(Context appContext, String host, int port) { System.setProperty("http.proxyHost", host); System.setProperty("http.proxyPort", port + ""); System.setProperty("https.proxyHost", host); System.setProperty("https.proxyPort", port + ""); try { Class applictionCls = Class.forName("android.app.Application"); Field loadedApkField = applictionCls.getDeclaredField("mLoadedApk"); loadedApkField.setAccessible(true); Object loadedApk = loadedApkField.get(appContext); Class loadedApkCls = Class.forName("android.app.LoadedApk"); Field receiversField = loadedApkCls.getDeclaredField("mReceivers"); receiversField.setAccessible(true); ArrayMap receivers = (ArrayMap) receiversField.get(loadedApk); for (Object receiverMap : receivers.values()) { for (Object rec : ((ArrayMap) receiverMap).keySet()) { Class clazz = rec.getClass(); if (clazz.getName().contains("ProxyChangeListener")) { Method onReceiveMethod = clazz.getDeclaredMethod("onReceive", Context.class, Intent.class); Intent intent = new Intent(Proxy.PROXY_CHANGE_ACTION); /***** In Lollipop, ProxyProperties went public as ProxyInfo *****/ final String CLASS_NAME = "android.net.ProxyInfo"; Class cls = Class.forName(CLASS_NAME); /***** ProxyInfo lacks constructors, use the static buildDirectProxy method instead *****/ Method buildDirectProxyMethod = cls.getMethod("buildDirectProxy", String.class, Integer.TYPE); Object proxyInfo = buildDirectProxyMethod.invoke(cls, host, port); intent.putExtra("proxy", (Parcelable) proxyInfo); onReceiveMethod.invoke(rec, appContext, intent); } } } } catch (Exception e) { Log.e(LOG_TAG, "Setting proxy with >= 5.0 API failed with", e); return false; } Log.d(LOG_TAG, "Setting proxy with >= 5.0 API successful!"); return true; }
Example 9
Source File: RetalDriverApplication.java From ratel with Apache License 2.0 | 4 votes |
@Override @SuppressWarnings("unchecked") public void onCreate() { super.onCreate(); String appClassName = getOriginApplicationName(); if (appClassName == null) { loadXposedModule(this); return; } //有值的话调用该Applicaiton Object currentActivityThread = currentActivityThread(); Object mBoundApplication = XposedHelpers.getObjectField("currentActivityThread", "mBoundApplication"); Object loadedApkInfo = XposedHelpers.getObjectField(mBoundApplication, "info"); //把当前进程的mApplication 设置成了null XposedHelpers.setObjectField(loadedApkInfo, "mApplication", null); Application oldApplication = (Application) XposedHelpers.getObjectField(currentActivityThread, "mInitialApplication"); //http://www.codeceo.com/article/android-context.html ArrayList<Application> mAllApplications = (ArrayList<Application>) XposedHelpers.getObjectField(currentActivityThread, "mAllApplications"); mAllApplications.remove(oldApplication);//删除oldApplication ApplicationInfo appinfoInLoadedApk = (ApplicationInfo) XposedHelpers.getObjectField(loadedApkInfo, "mApplicationInfo"); ApplicationInfo appinfoInAppBindData = (ApplicationInfo) XposedHelpers.getObjectField(mBoundApplication, "appInfo"); appinfoInLoadedApk.className = appClassName; appinfoInAppBindData.className = appClassName; loadXposedModule(this); //makeApplication 的时候,就会调用attachBaseContext方法 Application app = (Application) XposedHelpers.callMethod(loadedApkInfo, "makeApplication", false, null); XposedHelpers.setObjectField(currentActivityThread, "mInitialApplication", app); ArrayMap mProviderMap = (ArrayMap) XposedHelpers.getObjectField(currentActivityThread, "mProviderMap"); for (Object providerClientRecord : mProviderMap.values()) { Object localProvider = XposedHelpers.getObjectField(providerClientRecord, "mLocalProvider"); XposedHelpers.setObjectField(localProvider, "mContext", app); } app.onCreate(); }
Example 10
Source File: FileUtilsActivity.java From AndroidAnimationExercise with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mContext = this; setContentView(R.layout.activity_file_utils); mRecyclerView = findViewById(R.id.recyclerView); mRetry = findViewById(R.id.retry); mRxBus = findViewById(R.id.rxbus); items = new ArrayList<>(); mSugarAdapter = SugarAdapter.Builder.with(items) .add(LargeItemHolder.class) .add(SmallItemHolder.class) .build(); mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); mRecyclerView.setAdapter(mSugarAdapter); mSugarAdapter.addDispatcher(new SugarAdapter.Dispatcher<Item>() { @NotNull @Override public Class<? extends SugarHolder> dispatch(@NonNull Item data) { if (data.getTitle().length() < 40) { return LargeItemHolder.class; } return SmallItemHolder.class; } }); refreshList(); mRetry.setOnClickListener(v -> recyclerview()); mRxBus.setOnClickListener(v -> RxBus.getInstance().post(new SimpleEvent(FileUtilsActivity.class.getSimpleName()))); ArrayMap<String, String> arrayMap = new ArrayMap<>(); arrayMap.put("name", "mike"); arrayMap.put("address", "beijing"); for (String sets : arrayMap.keySet()) { Log.e(TAG, "onCreate: sets=" + sets); } for (String values : arrayMap.values()) { Log.e(TAG, "onCreate: values=" + values); } if (!TextUtils.isEmpty("3")) { } }
Example 11
Source File: WebViewProxyUtil.java From FaceSlim with GNU General Public License v2.0 | 4 votes |
/** * Set Proxy for Android 4.4 and above. */ @SuppressWarnings("all") private static boolean setKitKatWebViewProxy(Context appContext, String host, int port) { System.setProperty("http.proxyHost", host); System.setProperty("http.proxyPort", port + ""); System.setProperty("https.proxyHost", host); System.setProperty("https.proxyPort", port + ""); try { Class applictionCls = Class.forName("android.app.Application"); Field loadedApkField = applictionCls.getDeclaredField("mLoadedApk"); loadedApkField.setAccessible(true); Object loadedApk = loadedApkField.get(appContext); Class loadedApkCls = Class.forName("android.app.LoadedApk"); Field receiversField = loadedApkCls.getDeclaredField("mReceivers"); receiversField.setAccessible(true); ArrayMap receivers = (ArrayMap) receiversField.get(loadedApk); for (Object receiverMap : receivers.values()) { for (Object rec : ((ArrayMap) receiverMap).keySet()) { Class clazz = rec.getClass(); if (clazz.getName().contains("ProxyChangeListener")) { Method onReceiveMethod = clazz.getDeclaredMethod("onReceive", Context.class, Intent.class); Intent intent = new Intent(Proxy.PROXY_CHANGE_ACTION); /*********** optional, may be need in future *************/ final String CLASS_NAME = "android.net.ProxyProperties"; Class cls = Class.forName(CLASS_NAME); Constructor constructor = cls.getConstructor(String.class, Integer.TYPE, String.class); constructor.setAccessible(true); Object proxyProperties = constructor.newInstance(host, port, null); intent.putExtra("proxy", (Parcelable) proxyProperties); /*********** optional, may be need in future *************/ onReceiveMethod.invoke(rec, appContext, intent); } } } } catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException | IllegalArgumentException | NoSuchMethodException | InvocationTargetException | InstantiationException e) { Log.e(LOG_TAG, "Setting proxy with >= 4.4 API failed with error: ", e); return false; } Log.d(LOG_TAG, "Setting proxy with >= 4.4 API successful!"); return true; }
Example 12
Source File: WebGuiActivity.java From syncthing-android with Mozilla Public License 2.0 | 4 votes |
/** * Set webview proxy and sites that are not retrieved using proxy. * Compatible with KitKat or higher android version. * Returns boolean if successful. * Source: https://stackoverflow.com/a/26781539 */ @SuppressLint("PrivateApi") public static boolean setWebViewProxy(Context appContext, String host, int port, String exclusionList) { if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { // Not supported on android version lower than KitKat. return false; } Properties properties = System.getProperties(); properties.setProperty("http.proxyHost", host); properties.setProperty("http.proxyPort", Integer.toString(port)); properties.setProperty("https.proxyHost", host); properties.setProperty("https.proxyPort", Integer.toString(port)); properties.setProperty("http.nonProxyHosts", exclusionList); properties.setProperty("https.nonProxyHosts", exclusionList); try { Class applictionCls = Class.forName("android.app.Application"); Field loadedApkField = applictionCls.getDeclaredField("mLoadedApk"); loadedApkField.setAccessible(true); Object loadedApk = loadedApkField.get(appContext); Class loadedApkCls = Class.forName("android.app.LoadedApk"); Field receiversField = loadedApkCls.getDeclaredField("mReceivers"); receiversField.setAccessible(true); ArrayMap receivers = (ArrayMap) receiversField.get(loadedApk); for (Object receiverMap : receivers.values()) { for (Object rec : ((ArrayMap) receiverMap).keySet()) { Class clazz = rec.getClass(); if (clazz.getName().contains("ProxyChangeListener")) { Method onReceiveMethod = clazz.getDeclaredMethod("onReceive", Context.class, Intent.class); Intent intent = new Intent(Proxy.PROXY_CHANGE_ACTION); String CLASS_NAME; if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) { CLASS_NAME = "android.net.ProxyProperties"; } else { CLASS_NAME = "android.net.ProxyInfo"; } Class cls = Class.forName(CLASS_NAME); Constructor constructor = cls.getConstructor(String.class, Integer.TYPE, String.class); constructor.setAccessible(true); Object proxyProperties = constructor.newInstance(host, port, exclusionList); intent.putExtra("proxy", (Parcelable) proxyProperties); onReceiveMethod.invoke(rec, appContext, intent); } } } return true; } catch (Exception e) { Log.w(TAG, "setWebViewProxy exception", e); } return false; }