List of usage examples for android.app ActivityManager isUserAMonkey
public static boolean isUserAMonkey()
From source file:ca.rmen.android.poetassistant.main.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { if (BuildConfig.DEBUG && ActivityManager.isUserAMonkey()) { requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); }/*from w ww. j av a 2s . com*/ super.onCreate(savedInstanceState); Log.d(TAG, "onCreate() called with: " + "savedInstanceState = [" + savedInstanceState + "]"); mBinding = DataBindingUtil.setContentView(this, R.layout.activity_main); setSupportActionBar(mBinding.toolbar); Intent intent = getIntent(); Uri data = intent.getData(); mPagerAdapter = new PagerAdapter(this, getSupportFragmentManager(), intent); mPagerAdapter.registerDataSetObserver(mAdapterChangeListener); // Set up the ViewPager with the sections adapter. mBinding.viewPager.setAdapter(mPagerAdapter); mBinding.viewPager.setOffscreenPageLimit(5); mBinding.viewPager.addOnPageChangeListener(mOnPageChangeListener); mBinding.tabs.setupWithViewPager(mBinding.viewPager); AppBarLayoutHelper.enableAutoHide(mBinding); mAdapterChangeListener.onChanged(); // If the app was launched with a query for the a particular tab, focus on that tab. if (data != null && data.getHost() != null) { Tab tab = Tab.parse(data.getHost()); if (tab == null) tab = Tab.DICTIONARY; mBinding.viewPager.setCurrentItem(mPagerAdapter.getPositionForTab(tab)); } else if (Intent.ACTION_SEND.equals(intent.getAction())) { mBinding.viewPager.setCurrentItem(mPagerAdapter.getPositionForTab(Tab.READER)); } mSearch = new Search(this, mBinding.viewPager); loadDictionaries(); setVolumeControlStream(AudioManager.STREAM_MUSIC); }
From source file:com.meiste.greg.ptw.tab.QuestionsForm.java
@Override public void onClick(final View v) { if (ActivityManager.isUserAMonkey()) { Util.log("QuestionsForm: onClick: User is a monkey!"); return;/*from w w w. j av a 2 s.c o m*/ } final Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); ((Questions) getParentFragment()).onSubmitAnswers(gson.toJson(this)); }
From source file:com.meiste.greg.ptw.GameActivity.java
private void loadAd() { final Builder adReqBuilder = new AdRequest.Builder(); adReqBuilder.addKeyword("NASCAR"); adReqBuilder.addKeyword("racing"); if (BuildConfig.DEBUG) { adReqBuilder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR); adReqBuilder.addTestDevice("CB529BCBD1E778FAD10EE145EE29045F"); // Atrix 4G adReqBuilder.addTestDevice("36A52B9CBB347B995EA40ACDD0D36376"); // XOOM adReqBuilder.addTestDevice("E64392AEFC7C9A13D2A6A76E9EA034C4"); // RAZR }//from w w w .ja va 2s .com final String adUnitId = mContainer.getString(GtmHelper.KEY_AD_ID); if (!TextUtils.isEmpty(adUnitId) && (mAdView == null) && !ActivityManager.isUserAMonkey()) { mAdView = new AdView(this); mAdView.setAdListener(mAdListener); mAdView.setAdUnitId(adUnitId); mAdView.setAdSize(Util.str2AdSize(mContainer.getString(GtmHelper.KEY_AD_SIZE))); mAdView.setBackgroundColor(getResources().getColor(R.color.ad_background)); mAdView.loadAd(adReqBuilder.build()); } }
From source file:com.meiste.greg.ptw.tab.Standings.java
@Override public void onClick(final DialogInterface dialog, final int which) { if (which != DialogInterface.BUTTON_POSITIVE) { // Nothing to do return;//from w w w.j av a 2s . c om } if (ActivityManager.isUserAMonkey()) { Util.log("Standings: onClick: User is a monkey!"); return; } if (dialog == mPrivacyDialog) { final String json = new Gson().toJson(mPrivacyDialog.getNewName()); mConnecting = mChanged = true; notifyChanged(); GAE.getInstance(getActivity()).postPage(this, "standings", json); } else if (dialog == mFriendActionDialog) { Util.log("Toggling " + mFriendActionDialog.getPlayer().getName() + " friend status"); final FriendRequest fReq = new FriendRequest(mFriendActionDialog.getPlayer()); fReq.player.friend = !fReq.player.friend; mConnecting = mChanged = true; notifyChanged(); GAE.getInstance(getActivity()).postPage(mFriendListener, "friend", fReq.toJson()); } else if (dialog == mFriendPlayerDialog) { Util.log("Requesting to add " + mFriendPlayerDialog.getPlayerName() + " as friend"); final FriendRequest fReq = new FriendRequest(new Player()); fReq.player.name = mFriendPlayerDialog.getPlayerName(); fReq.player.friend = true; mConnecting = mChanged = true; notifyChanged(); GAE.getInstance(getActivity()).postPage(mFriendListener, "friend", fReq.toJson()); } else if (dialog == mFriendMethodDialog) { switch (mFriendMethodDialog.getSelectedMethod()) { case FriendMethodDialog.METHOD_MANUAL: Util.log("Adding friend via username"); showFriendPlayerDialog(); break; case FriendMethodDialog.METHOD_NFC: Util.log("Adding friend using NFC"); final FriendRequest fReq = new FriendRequest(mAdapter.getPlayer(), Gcm.getRegistrationId(getActivity().getApplicationContext())); final Intent intent = new Intent(getActivity(), NfcSendActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); intent.putExtra(NfcSendActivity.EXTRA_PLAYER_REQ, fReq.toJson()); startActivity(intent); break; } } }
From source file:com.zte.permissioncontrol.ui.PermissionControlPageActivity.java
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (ActivityManager.isUserAMonkey()) { Log.d(TAG, "Monkey is running"); return;// w w w. j av a2s.com } if (!mUserCheckedFlag) { Log.d(TAG, "mUserCheckedFlag is false , return "); return; } Log.d(TAG, "onCheckedChanged(),isChecked = " + isChecked); if (isChecked) { addUI(); PermControlUtils.enablePermissionControl(true, this); } else { // get the value from provider , it's 0 by default boolean isShowDlg = Settings.System.getInt(getContentResolver(), PermControlUtils.PERMISSION_SWITCH_OFF_DLG_STATE, 0) == 0; Log.d(TAG, "onCheckedChanged(), isShow alert Dlg = " + isShowDlg); if (isShowDlg) { // show alert dialog Intent intent = new Intent(); intent.setAction(UiUtils.ACTION_SWITCH_OFF_CONTROL_FROM_APP_PERM); startActivity(intent); } else { removeUI(); PermControlUtils.enablePermissionControl(false, this); } } }
From source file:ca.rmen.android.scrumchatter.main.MainActivity.java
@Override public void onBackPressed() { Log.v(TAG, "onBackPressed"); // Prevent the monkey from exiting the app, to maximize the time the monkey spends testing the app. if (ActivityManager.isUserAMonkey()) { Log.v(TAG, "Sorry, monkeys must stay in the cage"); return;//w w w .java 2s . c o m } super.onBackPressed(); }
From source file:com.landenlabs.all_devtool.SystemFragment.java
public void updateList() { // Time today = new Time(Time.getCurrentTimezone()); // today.setToNow(); // today.format(" %H:%M:%S") Date dt = new Date(); m_titleTime.setText(m_timeFormat.format(dt)); boolean expandAll = m_list.isEmpty(); m_list.clear();// w ww .j av a2 s . co m // Swap colors int color = m_rowColor1; m_rowColor1 = m_rowColor2; m_rowColor2 = color; ActivityManager actMgr = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE); try { String androidIDStr = Settings.Secure.getString(getContext().getContentResolver(), Settings.Secure.ANDROID_ID); addBuild("Android ID", androidIDStr); try { AdvertisingIdClient.Info adInfo = AdvertisingIdClient.getAdvertisingIdInfo(getContext()); final String adIdStr = adInfo.getId(); final boolean isLAT = adInfo.isLimitAdTrackingEnabled(); addBuild("Ad ID", adIdStr); } catch (IOException e) { // Unrecoverable error connecting to Google Play services (e.g., // the old version of the service doesn't support getting AdvertisingId). } catch (GooglePlayServicesNotAvailableException e) { // Google Play services is not available entirely. } /* try { InstanceID instanceID = InstanceID.getInstance(getContext()); if (instanceID != null) { // Requires a Google Developer project ID. String authorizedEntity = "<need to make this on google developer site>"; instanceID.getToken(authorizedEntity, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null); addBuild("Instance ID", instanceID.getId()); } } catch (Exception ex) { } */ ConfigurationInfo info = actMgr.getDeviceConfigurationInfo(); addBuild("OpenGL", info.getGlEsVersion()); } catch (Exception ex) { m_log.e(ex.getMessage()); } try { long heapSize = Debug.getNativeHeapSize(); // long maxHeap = Runtime.getRuntime().maxMemory(); // ConfigurationInfo cfgInfo = actMgr.getDeviceConfigurationInfo(); int largHeapMb = actMgr.getLargeMemoryClass(); int heapMb = actMgr.getMemoryClass(); MemoryInfo memInfo = new MemoryInfo(); actMgr.getMemoryInfo(memInfo); final String sFmtMB = "%.2f MB"; Map<String, String> listStr = new TreeMap<String, String>(); listStr.put("Mem Available (now)", String.format(sFmtMB, (double) memInfo.availMem / MB)); listStr.put("Mem LowWhenOnlyAvail", String.format(sFmtMB, (double) memInfo.threshold / MB)); if (Build.VERSION.SDK_INT >= 16) { listStr.put("Mem Installed", String.format(sFmtMB, (double) memInfo.totalMem / MB)); } listStr.put("Heap (this app)", String.format(sFmtMB, (double) heapSize / MB)); listStr.put("HeapMax (default)", String.format(sFmtMB, (double) heapMb)); listStr.put("HeapMax (large)", String.format(sFmtMB, (double) largHeapMb)); addBuild("Memory...", listStr); } catch (Exception ex) { m_log.e(ex.getMessage()); } try { List<ProcessErrorStateInfo> procErrList = actMgr.getProcessesInErrorState(); int errCnt = (procErrList == null ? 0 : procErrList.size()); procErrList = null; // List<RunningAppProcessInfo> procList = actMgr.getRunningAppProcesses(); int procCnt = actMgr.getRunningAppProcesses().size(); int srvCnt = actMgr.getRunningServices(100).size(); Map<String, String> listStr = new TreeMap<String, String>(); listStr.put("#Processes", String.valueOf(procCnt)); listStr.put("#Proc With Err", String.valueOf(errCnt)); listStr.put("#Services", String.valueOf(srvCnt)); // Requires special permission // int taskCnt = actMgr.getRunningTasks(100).size(); // listStr.put("#Tasks", String.valueOf(taskCnt)); addBuild("Processes...", listStr); } catch (Exception ex) { m_log.e("System-Processes %s", ex.getMessage()); } try { Map<String, String> listStr = new LinkedHashMap<String, String>(); listStr.put("LargeIconDensity", String.valueOf(actMgr.getLauncherLargeIconDensity())); listStr.put("LargeIconSize", String.valueOf(actMgr.getLauncherLargeIconSize())); putIf(listStr, "isRunningInTestHarness", "Yes", ActivityManager.isRunningInTestHarness()); putIf(listStr, "isUserAMonkey", "Yes", ActivityManager.isUserAMonkey()); addBuild("Misc...", listStr); } catch (Exception ex) { m_log.e("System-Misc %s", ex.getMessage()); } // --------------- Locale / Timezone ------------- try { Locale ourLocale = Locale.getDefault(); Date m_date = new Date(); TimeZone tz = TimeZone.getDefault(); Map<String, String> localeListStr = new LinkedHashMap<String, String>(); localeListStr.put("Locale Name", ourLocale.getDisplayName()); localeListStr.put(" Variant", ourLocale.getVariant()); localeListStr.put(" Country", ourLocale.getCountry()); localeListStr.put(" Country ISO", ourLocale.getISO3Country()); localeListStr.put(" Language", ourLocale.getLanguage()); localeListStr.put(" Language ISO", ourLocale.getISO3Language()); localeListStr.put(" Language Dsp", ourLocale.getDisplayLanguage()); localeListStr.put("TimeZoneID", tz.getID()); localeListStr.put(" DayLightSavings", tz.useDaylightTime() ? "Yes" : "No"); localeListStr.put(" In DLS", tz.inDaylightTime(m_date) ? "Yes" : "No"); localeListStr.put(" Short Name", tz.getDisplayName(false, TimeZone.SHORT, ourLocale)); localeListStr.put(" Long Name", tz.getDisplayName(false, TimeZone.LONG, ourLocale)); addBuild("Locale TZ...", localeListStr); } catch (Exception ex) { m_log.e("Locale/TZ %s", ex.getMessage()); } // --------------- Location Services ------------- try { Map<String, String> listStr = new LinkedHashMap<String, String>(); final LocationManager locMgr = (LocationManager) getActivity() .getSystemService(Context.LOCATION_SERVICE); GpsStatus gpsStatus = locMgr.getGpsStatus(null); if (gpsStatus != null) { listStr.put("Sec ToGetGPS", String.valueOf(gpsStatus.getTimeToFirstFix())); Iterable<GpsSatellite> satellites = gpsStatus.getSatellites(); Iterator<GpsSatellite> sat = satellites.iterator(); while (sat.hasNext()) { GpsSatellite satellite = sat.next(); putIf(listStr, String.format("Azm:%.0f, Elev:%.0f", satellite.getAzimuth(), satellite.getElevation()), String.format("%.2f Snr", satellite.getSnr()), satellite.usedInFix()); } } Location location = null; if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) { location = locMgr.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (null == location) location = locMgr.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (null == location) location = locMgr.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER); } if (null != location) { listStr.put(location.getProvider() + " lat,lng", String.format("%.3f, %.3f", location.getLatitude(), location.getLongitude())); } if (listStr.size() != 0) { List<String> gpsProviders = locMgr.getAllProviders(); int idx = 1; for (String providerName : gpsProviders) { LocationProvider provider = locMgr.getProvider(providerName); if (null != provider) { listStr.put(providerName, (locMgr.isProviderEnabled(providerName) ? "On " : "Off ") + String.format("Accuracy:%d Pwr:%d", provider.getAccuracy(), provider.getPowerRequirement())); } } addBuild("GPS...", listStr); } else addBuild("GPS", "Off"); } catch (Exception ex) { m_log.e(ex.getMessage()); } // --------------- Application Info ------------- ApplicationInfo appInfo = getActivity().getApplicationInfo(); if (null != appInfo) { Map<String, String> appList = new LinkedHashMap<String, String>(); try { appList.put("ProcName", appInfo.processName); appList.put("PkgName", appInfo.packageName); appList.put("DataDir", appInfo.dataDir); appList.put("SrcDir", appInfo.sourceDir); // appList.put("PkgResDir", getActivity().getPackageResourcePath()); // appList.put("PkgCodeDir", getActivity().getPackageCodePath()); String[] dbList = getActivity().databaseList(); if (dbList != null && dbList.length != 0) appList.put("DataBase", dbList[0]); // getActivity().getComponentName(). } catch (Exception ex) { } addBuild("AppInfo...", appList); } // --------------- Account Services ------------- final AccountManager accMgr = (AccountManager) getActivity().getSystemService(Context.ACCOUNT_SERVICE); if (null != accMgr) { Map<String, String> strList = new LinkedHashMap<String, String>(); try { for (Account account : accMgr.getAccounts()) { strList.put(account.name, account.type); } } catch (Exception ex) { m_log.e(ex.getMessage()); } addBuild("Accounts...", strList); } // --------------- Package Features ------------- PackageManager pm = getActivity().getPackageManager(); FeatureInfo[] features = pm.getSystemAvailableFeatures(); if (features != null) { Map<String, String> strList = new LinkedHashMap<String, String>(); for (FeatureInfo featureInfo : features) { strList.put(featureInfo.name, ""); } addBuild("Features...", strList); } // --------------- Sensor Services ------------- final SensorManager senMgr = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); if (null != senMgr) { Map<String, String> strList = new LinkedHashMap<String, String>(); // Sensor accelerometer = senMgr.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); // senMgr.registerListener(foo, accelerometer, SensorManager.SENSOR_DELAY_NORMAL); List<Sensor> listSensor = senMgr.getSensorList(Sensor.TYPE_ALL); try { for (Sensor sensor : listSensor) { strList.put(sensor.getName(), sensor.getVendor()); } } catch (Exception ex) { m_log.e(ex.getMessage()); } addBuild("Sensors...", strList); } try { if (Build.VERSION.SDK_INT >= 17) { final UserManager userMgr = (UserManager) getActivity().getSystemService(Context.USER_SERVICE); if (null != userMgr) { try { addBuild("UserName", userMgr.getUserName()); } catch (Exception ex) { m_log.e(ex.getMessage()); } } } } catch (Exception ex) { } try { Map<String, String> strList = new LinkedHashMap<String, String>(); int screenTimeout = Settings.System.getInt(getActivity().getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT); strList.put("ScreenTimeOut", String.valueOf(screenTimeout / 1000)); int rotate = Settings.System.getInt(getActivity().getContentResolver(), Settings.System.ACCELEROMETER_ROTATION); strList.put("RotateEnabled", String.valueOf(rotate)); if (Build.VERSION.SDK_INT >= 17) { // Global added in API 17 int adb = Settings.Global.getInt(getActivity().getContentResolver(), Settings.Global.ADB_ENABLED); strList.put("AdbEnabled", String.valueOf(adb)); } addBuild("Settings...", strList); } catch (Exception ex) { } if (expandAll) { // updateList(); int count = m_list.size(); for (int position = 0; position < count; position++) m_listView.expandGroup(position); } m_adapter.notifyDataSetChanged(); }
From source file:com.android.mail.compose.ComposeActivity.java
protected void sendOrSave(final boolean save, final boolean showToast) { // Check if user is a monkey. Monkeys can compose and hit send // button but are not allowed to send anything off the device. if (ActivityManager.isUserAMonkey()) { return;/* ww w .j a va 2s. c om*/ } final SendOrSaveCallback callback = new SendOrSaveCallback() { @Override public void initializeSendOrSave() { final Intent i = new Intent(ComposeActivity.this, EmptyService.class); // API 16+ allows for setClipData. For pre-16 we are going to open the fds // on the main thread. if (Utils.isRunningJellybeanOrLater()) { // Grant the READ permission for the attachments to the service so that // as long as the service stays alive we won't hit PermissionExceptions. final ClipDescription desc = new ClipDescription("attachment_uris", new String[] { ClipDescription.MIMETYPE_TEXT_URILIST }); ClipData clipData = null; for (Attachment a : mAttachmentsView.getAttachments()) { if (a != null && !Utils.isEmpty(a.contentUri)) { final ClipData.Item uriItem = new ClipData.Item(a.contentUri); if (clipData == null) { clipData = new ClipData(desc, uriItem); } else { clipData.addItem(uriItem); } } } i.setClipData(clipData); i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } synchronized (PENDING_SEND_OR_SAVE_TASKS_NUM) { if (PENDING_SEND_OR_SAVE_TASKS_NUM.getAndAdd(1) == 0) { // Start service so we won't be killed if this app is // put in the background. startService(i); } } if (sTestSendOrSaveCallback != null) { sTestSendOrSaveCallback.initializeSendOrSave(); } } @Override public void notifyMessageIdAllocated(SendOrSaveMessage sendOrSaveMessage, Message message) { synchronized (mDraftLock) { mDraftId = message.id; mDraft = message; if (sRequestMessageIdMap != null) { sRequestMessageIdMap.put(sendOrSaveMessage.mRequestId, mDraftId); } // Cache request message map, in case the process is killed saveRequestMap(); } if (sTestSendOrSaveCallback != null) { sTestSendOrSaveCallback.notifyMessageIdAllocated(sendOrSaveMessage, message); } } @Override public long getMessageId() { synchronized (mDraftLock) { return mDraftId; } } @Override public void sendOrSaveFinished(SendOrSaveMessage message, boolean success) { // Update the last sent from account. if (mAccount != null) { MailAppProvider.getInstance().setLastSentFromAccount(mAccount.uri.toString()); } if (success) { // Successfully sent or saved so reset change markers discardChanges(); } else { // A failure happened with saving/sending the draft // TODO(pwestbro): add a better string that should be used // when failing to send or save Toast.makeText(ComposeActivity.this, R.string.send_failed, Toast.LENGTH_SHORT).show(); } synchronized (PENDING_SEND_OR_SAVE_TASKS_NUM) { if (PENDING_SEND_OR_SAVE_TASKS_NUM.addAndGet(-1) == 0) { // Stop service so we can be killed. stopService(new Intent(ComposeActivity.this, EmptyService.class)); } } if (sTestSendOrSaveCallback != null) { sTestSendOrSaveCallback.sendOrSaveFinished(message, success); } } }; setAccount(mReplyFromAccount.account); final Spanned body = removeComposingSpans(mBodyView.getText()); callback.initializeSendOrSave(); // For pre-JB we need to open the fds on the main thread final Bundle attachmentFds; if (!Utils.isRunningJellybeanOrLater()) { attachmentFds = initializeAttachmentFds(this, mAttachmentsView.getAttachments()); } else { attachmentFds = null; } // Generate a unique message id for this request mRequestId = sRandom.nextInt(); SEND_SAVE_TASK_HANDLER.post(new Runnable() { @Override public void run() { final Message msg = createMessage(mReplyFromAccount, mRefMessage, getMode(), body); sendOrSaveInternal(ComposeActivity.this, mRequestId, mReplyFromAccount, mDraftAccount, msg, mRefMessage, mQuotedTextView.getQuotedTextIfIncluded(), callback, save, mComposeMode, mExtraValues, attachmentFds); } }); // Don't display the toast if the user is just changing the orientation, // but we still need to save the draft to the cursor because this is how we restore // the attachments when the configuration change completes. if (showToast && (getChangingConfigurations() & ActivityInfo.CONFIG_ORIENTATION) == 0) { Toast.makeText(this, save ? R.string.message_saved : R.string.sending_message, Toast.LENGTH_LONG) .show(); } // Need to update variables here because the send or save completes // asynchronously even though the toast shows right away. discardChanges(); updateSaveUi(); // If we are sending, finish the activity if (!save) { finish(); } }