List of usage examples for android.content.pm PackageManager getApplicationInfo
public abstract ApplicationInfo getApplicationInfo(String packageName, @ApplicationInfoFlags int flags) throws NameNotFoundException;
From source file:com.android.calendar.EventInfoFragment.java
private void updateCustomAppButton() { buttonSetup: {/*w ww. j a v a 2 s . c o m*/ final Button launchButton = (Button) mView.findViewById(R.id.launch_custom_app_button); if (launchButton == null) break buttonSetup; final String customAppPackage = mEventCursor.getString(EVENT_INDEX_CUSTOM_APP_PACKAGE); final String customAppUri = mEventCursor.getString(EVENT_INDEX_CUSTOM_APP_URI); if (TextUtils.isEmpty(customAppPackage) || TextUtils.isEmpty(customAppUri)) break buttonSetup; PackageManager pm = mContext.getPackageManager(); if (pm == null) break buttonSetup; ApplicationInfo info; try { info = pm.getApplicationInfo(customAppPackage, 0); if (info == null) break buttonSetup; } catch (NameNotFoundException e) { break buttonSetup; } Uri uri = ContentUris.withAppendedId(Events.CONTENT_URI, mEventId); final Intent intent = new Intent(CalendarContract.ACTION_HANDLE_CUSTOM_EVENT, uri); intent.setPackage(customAppPackage); intent.putExtra(CalendarContract.EXTRA_CUSTOM_APP_URI, customAppUri); intent.putExtra(EXTRA_EVENT_BEGIN_TIME, mStartMillis); // See if we have a taker for our intent if (pm.resolveActivity(intent, 0) == null) break buttonSetup; Drawable icon = pm.getApplicationIcon(info); if (icon != null) { Drawable[] d = launchButton.getCompoundDrawables(); icon.setBounds(0, 0, mCustomAppIconSize, mCustomAppIconSize); launchButton.setCompoundDrawables(icon, d[1], d[2], d[3]); } CharSequence label = pm.getApplicationLabel(info); if (label != null && label.length() != 0) { launchButton.setText(label); } else if (icon == null) { // No icon && no label. Hide button? break buttonSetup; } // Launch custom app launchButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { startActivityForResult(intent, 0); } catch (ActivityNotFoundException e) { // Shouldn't happen as we checked it already setVisibilityCommon(mView, R.id.launch_custom_app_container, View.GONE); } } }); setVisibilityCommon(mView, R.id.launch_custom_app_container, View.VISIBLE); return; } setVisibilityCommon(mView, R.id.launch_custom_app_container, View.GONE); return; }
From source file:com.dattasmoon.pebble.plugin.NotificationService.java
@Override public void onAccessibilityEvent(AccessibilityEvent event) { // handle the prefs changing, because of how accessibility services // work, sharedprefsonchange listeners don't work if (watchFile.lastModified() > lastChange) { loadPrefs();/* w w w . j av a 2s .c o m*/ } if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Service: Mode is: " + String.valueOf(mode.ordinal())); } // if we are off, don't do anything. if (mode == Mode.OFF) { if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Service: Mode is off, not sending any notifications"); } return; } //handle quiet hours if (quiet_hours) { Calendar c = Calendar.getInstance(); Date now = new Date(0, 0, 0, c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE)); if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Checking quiet hours. Now: " + now.toString() + " vs " + quiet_hours_before.toString() + " and " + quiet_hours_after.toString()); } if (quiet_hours_before.after(quiet_hours_after)) { if (now.after(quiet_hours_after) && now.before(quiet_hours_before)) { if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Time is during quiet time. Returning."); } return; } } else if (now.before(quiet_hours_before) || now.after(quiet_hours_after)) { if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Time is before or after the quiet hours time. Returning."); } return; } } // handle if they only want notifications if (notifications_only) { if (event != null) { Parcelable parcelable = event.getParcelableData(); if (!(parcelable instanceof Notification)) { if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Event is not a notification and notifications only is enabled. Returning."); } return; } } } if (no_ongoing_notifs) { Parcelable parcelable = event.getParcelableData(); if (parcelable instanceof Notification) { Notification notif = (Notification) parcelable; if ((notif.flags & Notification.FLAG_ONGOING_EVENT) == Notification.FLAG_ONGOING_EVENT) { if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Event is a notification, notification flag contains ongoing, and no ongoing notification is true. Returning."); } return; } } else { if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Event is not a notification."); } } } // Handle the do not disturb screen on settings PowerManager powMan = (PowerManager) this.getSystemService(Context.POWER_SERVICE); if (Constants.IS_LOGGABLE) { Log.d(Constants.LOG_TAG, "NotificationService.onAccessibilityEvent: notifScreenOn=" + notifScreenOn + " screen=" + powMan.isScreenOn()); } if (!notifScreenOn && powMan.isScreenOn()) { return; } if (event == null) { if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Event is null. Returning."); } return; } if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Event: " + event.toString()); } // main logic PackageManager pm = getPackageManager(); String eventPackageName; if (event.getPackageName() != null) { eventPackageName = event.getPackageName().toString(); } else { eventPackageName = ""; } if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Service package list is: "); for (String strPackage : packages) { Log.i(Constants.LOG_TAG, strPackage); } Log.i(Constants.LOG_TAG, "End Service package list"); } switch (mode) { case EXCLUDE: // exclude functionality if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Mode is set to exclude"); } for (String packageName : packages) { if (packageName.equalsIgnoreCase(eventPackageName)) { if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, packageName + " == " + eventPackageName + " which is on the exclude list. Returning."); } return; } } break; case INCLUDE: // include only functionality if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Mode is set to include only"); } boolean found = false; for (String packageName : packages) { if (packageName.equalsIgnoreCase(eventPackageName)) { found = true; break; } } if (!found) { Log.i(Constants.LOG_TAG, eventPackageName + " was not found in the include list. Returning."); return; } break; } // get the title String title = ""; try { boolean renamed = false; for (int i = 0; i < pkg_renames.length(); i++) { if (pkg_renames.getJSONObject(i).getString("pkg").equalsIgnoreCase(eventPackageName)) { renamed = true; title = pkg_renames.getJSONObject(i).getString("to"); } } if (!renamed) { title = pm.getApplicationLabel(pm.getApplicationInfo(eventPackageName, 0)).toString(); } } catch (NameNotFoundException e) { title = eventPackageName; } catch (JSONException e) { title = eventPackageName; } // get the notification text String notificationText = event.getText().toString(); // strip the first and last characters which are [ and ] notificationText = notificationText.substring(1, notificationText.length() - 1); if (notification_extras) { if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Fetching extras from notification"); } Parcelable parcelable = event.getParcelableData(); if (parcelable instanceof Notification) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { notificationText += "\n" + getExtraBigData((Notification) parcelable, notificationText.trim()); } else { notificationText += "\n" + getExtraData((Notification) parcelable, notificationText.trim()); } } } // Check ignore lists for (int i = 0; i < ignores.length(); i++) { try { JSONObject ignore = ignores.getJSONObject(i); String app = ignore.getString("app"); boolean exclude = ignore.optBoolean("exclude", true); boolean case_insensitive = ignore.optBoolean("insensitive", true); if ((!app.equals("-1")) && (!eventPackageName.equalsIgnoreCase(app))) { //this rule doesn't apply to all apps and this isn't the app we're looking for. continue; } String regex = ""; if (case_insensitive) { regex += "(?i)"; } if (!ignore.getBoolean("raw")) { regex += Pattern.quote(ignore.getString("match")); } else { regex += ignore.getString("match"); } Pattern p = Pattern.compile(regex); Matcher m = p.matcher(notificationText); if (m.find()) { if (exclude) { if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Notification text of '" + notificationText + "' matches: '" + regex + "' and exclude is on. Returning"); } return; } } else { if (!exclude) { if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Notification text of '" + notificationText + "' does not match: '" + regex + "' and include is on. Returning"); } return; } } } catch (JSONException e) { continue; } } // Send the alert to Pebble sendToPebble(title, notificationText); if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, event.toString()); Log.i(Constants.LOG_TAG, event.getPackageName().toString()); } }
From source file:com.apptentive.android.sdk.ApptentiveInternal.java
public boolean init() { boolean bRet = true; codePointStore.init();//from www . ja v a2s. c o m /* If Message Center feature has never been used before, don't initialize message polling thread. * Message Center feature will be seen as used, if one of the following conditions has been met: * 1. Message Center has been opened for the first time * 2. The first Push is received which would open Message Center * 3. An unreadMessageCountListener() is set up */ boolean featureEverUsed = prefs.getBoolean(Constants.PREF_KEY_MESSAGE_CENTER_FEATURE_USED, false); if (featureEverUsed) { messageManager.init(); } conversationToken = prefs.getString(Constants.PREF_KEY_CONVERSATION_TOKEN, null); conversationId = prefs.getString(Constants.PREF_KEY_CONVERSATION_ID, null); personId = prefs.getString(Constants.PREF_KEY_PERSON_ID, null); apptentiveToolbarTheme = appContext.getResources().newTheme(); boolean apptentiveDebug = false; String logLevelOverride = null; String manifestApiKey = null; try { appPackageName = appContext.getPackageName(); PackageManager packageManager = appContext.getPackageManager(); PackageInfo packageInfo = packageManager.getPackageInfo(appPackageName, PackageManager.GET_META_DATA | PackageManager.GET_RECEIVERS); ApplicationInfo ai = packageInfo.applicationInfo; Bundle metaData = ai.metaData; if (metaData != null) { manifestApiKey = Util.trim(metaData.getString(Constants.MANIFEST_KEY_APPTENTIVE_API_KEY)); logLevelOverride = Util.trim(metaData.getString(Constants.MANIFEST_KEY_APPTENTIVE_LOG_LEVEL)); apptentiveDebug = metaData.getBoolean(Constants.MANIFEST_KEY_APPTENTIVE_DEBUG); } // Used for application theme inheritance if the theme is an AppCompat theme. setApplicationDefaultTheme(ai.theme); AppRelease appRelease = AppRelease.generateCurrentAppRelease(appContext); isAppDebuggable = appRelease.getDebug(); currentVersionCode = appRelease.getVersionCode(); currentVersionName = appRelease.getVersionName(); VersionHistoryEntry lastVersionEntrySeen = VersionHistoryStore.getLastVersionSeen(); if (lastVersionEntrySeen == null) { onVersionChanged(null, currentVersionCode, null, currentVersionName, appRelease); } else { int lastSeenVersionCode = lastVersionEntrySeen.getVersionCode(); Apptentive.Version lastSeenVersionNameVersion = new Apptentive.Version(); lastSeenVersionNameVersion.setVersion(lastVersionEntrySeen.getVersionName()); if (!(currentVersionCode == lastSeenVersionCode) || !currentVersionName.equals(lastSeenVersionNameVersion.getVersion())) { onVersionChanged(lastVersionEntrySeen.getVersionCode(), currentVersionCode, lastVersionEntrySeen.getVersionName(), currentVersionName, appRelease); } } defaultAppDisplayName = packageManager .getApplicationLabel(packageManager.getApplicationInfo(packageInfo.packageName, 0)).toString(); // Prevent delayed run-time exception if the app upgrades from pre-2.0 and doesn't remove NetworkStateReceiver from manifest ActivityInfo[] registered = packageInfo.receivers; if (registered != null) { for (ActivityInfo activityInfo : registered) { // Throw assertion error when relict class found in manifest. if (activityInfo.name.equals("com.apptentive.android.sdk.comm.NetworkStateReceiver")) { throw new AssertionError( "NetworkStateReceiver has been removed from Apptentive SDK, please make sure it's also removed from manifest file"); } } } } catch (Exception e) { ApptentiveLog.e("Unexpected error while reading application or package info.", e); bRet = false; } // Set debuggable and appropriate log level. if (apptentiveDebug) { ApptentiveLog.i("Apptentive debug logging set to VERBOSE."); setMinimumLogLevel(ApptentiveLog.Level.VERBOSE); } else if (logLevelOverride != null) { ApptentiveLog.i("Overriding log level: %s", logLevelOverride); setMinimumLogLevel(ApptentiveLog.Level.parse(logLevelOverride)); } else { if (isAppDebuggable) { setMinimumLogLevel(ApptentiveLog.Level.VERBOSE); } } ApptentiveLog.i("Debug mode enabled? %b", isAppDebuggable); String lastSeenSdkVersion = prefs.getString(Constants.PREF_KEY_LAST_SEEN_SDK_VERSION, ""); if (!lastSeenSdkVersion.equals(Constants.APPTENTIVE_SDK_VERSION)) { onSdkVersionChanged(appContext, lastSeenSdkVersion, Constants.APPTENTIVE_SDK_VERSION); } // The apiKey can be passed in programmatically, or we can fallback to checking in the manifest. if (TextUtils.isEmpty(apiKey) && !TextUtils.isEmpty(manifestApiKey)) { apiKey = manifestApiKey; } if (TextUtils.isEmpty(apiKey) || apiKey.contains(Constants.EXAMPLE_API_KEY_VALUE)) { String errorMessage = "The Apptentive API Key is not defined. You may provide your Apptentive API Key in Apptentive.register(), or in as meta-data in your AndroidManifest.xml.\n" + "<meta-data android:name=\"apptentive_api_key\"\n" + " android:value=\"@string/your_apptentive_api_key\"/>"; if (isAppDebuggable) { throw new RuntimeException(errorMessage); } else { ApptentiveLog.e(errorMessage); } } else { ApptentiveLog.d("Using cached Apptentive API Key"); } ApptentiveLog.d("Apptentive API Key: %s", apiKey); // Grab app info we need to access later on. androidId = Settings.Secure.getString(appContext.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID); ApptentiveLog.d("Android ID: ", androidId); ApptentiveLog.d("Default Locale: %s", Locale.getDefault().toString()); ApptentiveLog.d("Conversation id: %s", prefs.getString(Constants.PREF_KEY_CONVERSATION_ID, "null")); return bRet; }
From source file:com.linkbubble.Settings.java
public void updateBrowsers() { if (mBrowsers == null) { mBrowsers = new Vector<Intent>(); mBrowserPackageNames = new ArrayList<String>(); } else {/*from ww w. ja v a 2 s. c o m*/ mBrowsers.clear(); mBrowserPackageNames.clear(); } PackageManager packageManager = mContext.getPackageManager(); Intent queryIntent = new Intent(); queryIntent.setAction(Intent.ACTION_VIEW); queryIntent.setData(Uri.parse("http://www.fdasfjsadfdsfas.com")); // Something stupid that no non-browser app will handle List<ResolveInfo> resolveInfos = packageManager.queryIntentActivities(queryIntent, PackageManager.GET_RESOLVED_FILTER); String fallbackDefaultBrowserPackageName = null; String fallbackDefaultBrowserActivityClassName = null; for (ResolveInfo resolveInfo : resolveInfos) { IntentFilter filter = resolveInfo.filter; if (filter != null && filter.hasAction(Intent.ACTION_VIEW) && filter.hasCategory(Intent.CATEGORY_BROWSABLE)) { // Ignore LinkBubble from this list if (resolveInfo.activityInfo.packageName.equals(BuildConfig.APPLICATION_ID)) { mLinkBubbleEntryActivityResolveInfo = resolveInfo; } else if (Util.isValidBrowserPackageName(resolveInfo.activityInfo.packageName)) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setClassName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name); mBrowsers.add(intent); mBrowserPackageNames.add(resolveInfo.activityInfo.packageName); if (resolveInfo.activityInfo.packageName .equals(mContext.getResources().getString(R.string.tab_based_browser_id_name))) { fallbackDefaultBrowserPackageName = resolveInfo.activityInfo.packageName; fallbackDefaultBrowserActivityClassName = resolveInfo.activityInfo.name; } } } } String defaultBrowserPackage = mSharedPreferences.getString(PREFERENCE_DEFAULT_BROWSER_PACKAGE_NAME, null); //String rightConsumeBubblePackageName = mSharedPreferences.getString(PREFERENCE_RIGHT_CONSUME_BUBBLE_PACKAGE_NAME, null); String leftConsumeBubblePackageName = mSharedPreferences .getString(PREFERENCE_LEFT_CONSUME_BUBBLE_PACKAGE_NAME, null); if (fallbackDefaultBrowserPackageName != null) { try { ApplicationInfo applicationInfo = packageManager .getApplicationInfo(fallbackDefaultBrowserPackageName, 0); String defaultBrowserLabel = packageManager.getApplicationLabel(applicationInfo).toString(); if (defaultBrowserPackage == null || !doesPackageExist(packageManager, defaultBrowserPackage)) { SharedPreferences.Editor editor = mSharedPreferences.edit(); editor.putString(PREFERENCE_DEFAULT_BROWSER_LABEL, defaultBrowserLabel); editor.putString(PREFERENCE_DEFAULT_BROWSER_PACKAGE_NAME, fallbackDefaultBrowserPackageName); editor.commit(); } if (leftConsumeBubblePackageName != null && !doesPackageExist(packageManager, leftConsumeBubblePackageName)) { setConsumeBubble(Constant.BubbleAction.ConsumeLeft, Constant.ActionType.View, defaultBrowserLabel, fallbackDefaultBrowserPackageName, fallbackDefaultBrowserActivityClassName); } } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } } }
From source file:com.klinker.android.launcher.launcher3.Launcher.java
protected boolean isLauncherPreinstalled() { if (mLauncherCallbacks != null) { return mLauncherCallbacks.isLauncherPreinstalled(); }// www . j av a 2 s. c om PackageManager pm = getPackageManager(); try { ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0); if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { return true; } else { return false; } } catch (NameNotFoundException e) { e.printStackTrace(); return false; } }
From source file:org.uguess.android.sysinfo.SiragonManager.java
String generateTextReport(boolean[] items) { StringBuffer sb = new StringBuffer(); createTextHeader(getActivity(), sb, "Android Sragon Report - I&D " //$NON-NLS-1$ + new Date().toLocaleString()); if (items[BASIC_INFO]) { sb.append("####################\n"); sb.append(getString(R.string.tab_info)).append('\n'); sb.append(HEADER_SPLIT);//from ww w .j a v a 2 s . com sb.append("* ") //$NON-NLS-1$ .append(getString(R.string.sd_storage)).append(":\n"); //$NON-NLS-1$ String[] info = getExternalStorageInfo(); if (info == null) { sb.append(getString(R.string.info_not_available)); } else { sb.append(getString(R.string.storage_external, info[0], info[1]) + "\n"); } sb.append("####################\n"); //$NON-NLS-1$ sb.append("* ") //$NON-NLS-1$ .append(getString(R.string.a2sd_storage) + ":").append("\n"); //$NON-NLS-2$ info = getA2SDStorageInfo(); if (info == null) { sb.append(getString(R.string.info_not_available)); sb.append("\n"); } else { sb.append(getString(R.string.storage_summary, info[0], info[1])); sb.append("\n"); } sb.append("####################\n"); //$NON-NLS-1$ sb.append("* ") //$NON-NLS-1$ .append(getString(R.string.display) + ":").append("\n"); //$NON-NLS-2$ String[] info2 = getInfoDisplay(); if (info2 == null) { sb.append(getString(R.string.info_not_available)); } else { for (int i = 0; i < info2.length; i++) { sb.append(getString(R.string.info_display, info2[i])).append("\n"); } } sb.append("####################\n"); //$NON-NLS-1$ sb.append("* ") //$NON-NLS-1$ .append(getString(R.string.camera_back_img_support)).append("\n"); //$NON-NLS-1$ info2 = getSupportedPreviewSizes(0); if (info2 == null) { sb.append(getString(R.string.info_not_available)); } else { for (int i = 0; i < info2.length; i++) { sb.append(getString(R.string.support_image_back, info2[i])).append("\n"); } } sb.append("####################\n"); //$NON-NLS-1$ sb.append("* ") //$NON-NLS-1$ .append(getString(R.string.camera_back_vid_support)).append("\n"); //$NON-NLS-1$ info2 = getSupportedPreviewSizesVideo(0); if (info2 == null) { sb.append(getString(R.string.info_not_available)); } else { for (int i = 0; i < info2.length; i++) { sb.append(getString(R.string.support_video_back, info2[i])).append("\n"); } } sb.append("####################\n"); //$NON-NLS-1$ ////////////////////////////////////////////////////////////////////////////////// sb.append("* ") //$NON-NLS-1$ .append(getString(R.string.camera_other_feature) + ":").append("\n"); //$NON-NLS-2$ info2 = getSupportedOtherCamera(0); if (info2 == null) { sb.append(getString(R.string.info_not_available)); } else { for (int i = 0; i < info2.length; i++) { sb.append(getString(R.string.camera_des_feature, info2[i])).append("\n"); } } sb.append("####################\n"); //$NON-NLS-1$ sb.append("* ") //$NON-NLS-1$ .append(getString(R.string.camera_front_img_support)).append("\n"); //$NON-NLS-1$ info2 = getSupportedPreviewSizes(1); if (info2 == null) { sb.append(getString(R.string.info_not_available)); } else { for (int i = 0; i < info2.length; i++) { sb.append(getString(R.string.support_image_front, info2[i])).append("\n"); } } sb.append("####################\n"); //$NON-NLS-1$ sb.append("* ") //$NON-NLS-1$ .append(getString(R.string.camera_front_vid_support)).append("\n"); //$NON-NLS-1$ info2 = getSupportedPreviewSizesVideo(1); if (info2 == null) { sb.append(getString(R.string.info_not_available)); } else { for (int i = 0; i < info2.length; i++) { sb.append(getString(R.string.support_video_front, info2[i])).append("\n"); } } sb.append("####################\n"); //$NON-NLS-1$ sb.append("* ") //$NON-NLS-1$ .append(getString(R.string.camera_feature)).append("\n"); //$NON-NLS-1$} info2 = getAvailableFeatureCamera(); if (info2 == null) { sb.append(getString(R.string.info_not_available)); } else { for (int i = 0; i < info2.length; i++) { sb.append(getString(R.string.camera_all_feature, info2[i])).append("\n"); } } sb.append("####################\n"); //$NON-NLS-1$*/ sb.append("* ") //$NON-NLS-1$ .append(getString(R.string.camera_back_available)).append(":").append("\n"); //$NON-NLS-2$ int cams = getNumberCamera(); if (cams == 0) { sb.append(getString(R.string.info_not_available)); } else { sb.append(getString(R.string.number_cams, cams) + "\n"); } sb.append("####################\n"); //$NON-NLS-1$ sb.append("* ") //$NON-NLS-1$ .append(getString(R.string.camera_flash_available) + ":").append("\n"); //$NON-NLS-2$} boolean flash = getAvailableFlash(); if (flash == false) { sb.append(getString(R.string.info_not_available) + "\n"); } else { sb.append(getString(R.string.flash_available, flash) + "\n"); } sb.append("####################\n"); //$NON-NLS-1$ //////////////////////////////////////////////////////////////////////////////////////7 sb.append("* ") //$NON-NLS-1$ .append(getString(R.string.internal_storage) + ":").append("\n"); //$NON-NLS-2$ info = getInternalStorageInfo(); if (info == null) { sb.append(getString(R.string.info_not_available) + "\n"); } else { sb.append(getString(R.string.storage_summary, info[0], info[1]) + "\n"); } sb.append("####################\n"); //$NON-NLS-1$ sb.append("* ") //$NON-NLS-1$ .append(getString(R.string.system_storage)).append(":\n"); //$NON-NLS-1$ info = getSystemStorageInfo(); if (info == null) { sb.append(getString(R.string.info_not_available) + "\n"); } else { sb.append(getString(R.string.storage_summary, info[0], info[1]) + "\n"); } sb.append("####################\n"); //$NON-NLS-1$ sb.append("* ") //$NON-NLS-1$ .append(getString(R.string.cache_storage)).append(":\n"); //$NON-NLS-1$ info = getCacheStorageInfo(); if (info == null) { sb.append(getString(R.string.info_not_available) + "\n"); } else { sb.append(getString(R.string.storage_summary, info[0], info[1]) + "\n"); } sb.append("####################\n"); //$NON-NLS-1$ sb.append("* ") //$NON-NLS-1$ .append(getString(R.string.memory)).append(":\n"); //$NON-NLS-1$ info = getMemInfo(); if (info == null) { sb.append(getString(R.string.info_not_available) + "\n"); } else { sb.append(getString(R.string.storage_summary, info[0], info[2]) + getString(R.string.idle_info, info[1]) + "\n"); } sb.append("####################\n"); //$NON-NLS-1$ sb.append("* ") //$NON-NLS-1$ .append(getString(R.string.processor) + ":").append("\n") //$NON-NLS-2$ .append(getCpuInfo() + "\n").append("####################\n"); //$NON-NLS-2$ String nInfo = getNetAddressInfo(); sb.append("* ") //$NON-NLS-1$ .append(getString(R.string.net_address) + ":").append("\n") //$NON-NLS-2$ .append(nInfo == null ? getString(R.string.info_not_available) + "\n" : nInfo + "\n") .append("####################\n"); //$NON-NLS-1$ //sb.append( '\n' ); try { File f = new File(F_SCALE_FREQ); if (f.exists()) { sb.append(getString(R.string.sc_freq)); readRawText(sb, new FileInputStream(f)); } else { sb.append(getString(R.string.no_sc_freq_info)).append('\n'); } sb.append("####################\n"); f = new File(F_CPU_INFO); if (f.exists()) { readRawText(sb, new FileInputStream(f)); } else { sb.append(getString(R.string.no_cpu_info)).append('\n'); } sb.append("####################\n"); f = new File(F_MEM_INFO); if (f.exists()) { readRawText(sb, new FileInputStream(f)); } else { sb.append(getString(R.string.no_mem_info)).append('\n'); } sb.append("####################\n"); f = new File(F_MOUNT_INFO); if (f.exists()) { readRawText(sb, new FileInputStream(f)); } else { sb.append(getString(R.string.no_mount_info)).append('\n'); } sb.append("####################\n"); } catch (Exception e) { Log.e(SiragonManager.class.getName(), e.getLocalizedMessage(), e); } } if (items[APPLICATIONS]) { sb.append(HEADER_SPLIT); sb.append(getString(R.string.tab_apps) + ":").append('\n'); PackageManager pm = getActivity().getPackageManager(); List<PackageInfo> pkgs = pm.getInstalledPackages(0); if (pkgs != null) { for (int i = 0, size = pkgs.size(); i < size; i++) { PackageInfo pkg = pkgs.get(i); sb.append(pkg.packageName).append(" <") //$NON-NLS-1$ .append(pkg.versionName).append(" (") //$NON-NLS-1$ .append(pkg.versionCode).append(")>"); //$NON-NLS-1$ if (pkg.applicationInfo != null) { sb.append("\t: ") //$NON-NLS-1$ .append(pkg.applicationInfo.loadLabel(pm)).append(" | ") //$NON-NLS-1$ .append(pkg.applicationInfo.flags).append(" | ") //$NON-NLS-1$ .append(pkg.applicationInfo.sourceDir); } sb.append('\n'); } } sb.append("####################\n"); } if (items[PROCESSES]) { sb.append(HEADER_SPLIT); sb.append(getString(R.string.tab_procs) + ":").append('\n'); ActivityManager am = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE); List<RunningAppProcessInfo> procs = am.getRunningAppProcesses(); if (procs != null) { PackageManager pm = getActivity().getPackageManager(); for (int i = 0, size = procs.size(); i < size; i++) { RunningAppProcessInfo proc = procs.get(i); sb.append('<').append(getImportance(proc)).append("> [") //$NON-NLS-1$ .append(proc.pid).append("]\t:\t"); //$NON-NLS-1$ sb.append(proc.processName); try { ApplicationInfo ai = pm.getApplicationInfo(proc.processName, 0); if (ai != null) { CharSequence label = pm.getApplicationLabel(ai); if (label != null && !label.equals(proc.processName)) { sb.append(" ( ") //$NON-NLS-1$ .append(label).append(" )"); //$NON-NLS-1$ } } } catch (NameNotFoundException e) { // ignore this error } sb.append('\n'); } } sb.append("####################\n"); } if (items[NETSTATES]) { sb.append(HEADER_SPLIT); sb.append(getString(R.string.tab_netstat) + ":").append('\n'); try { readRawText(sb, new FileInputStream("/proc/net/tcp")); //$NON-NLS-1$ sb.append('\n'); readRawText(sb, new FileInputStream("/proc/net/udp")); //$NON-NLS-1$ } catch (Exception e) { Log.e(SiragonManager.class.getName(), e.getLocalizedMessage(), e); } sb.append("####################\n"); } if (items[DMESG_LOG]) { sb.append(HEADER_SPLIT); sb.append("Dmesg " + getString(R.string.log) + ":").append('\n'); //$NON-NLS-1$ try { Process proc = Runtime.getRuntime().exec("dmesg"); //$NON-NLS-1$ readRawText(sb, proc.getInputStream()); } catch (Exception e) { Log.e(SiragonManager.class.getName(), e.getLocalizedMessage(), e); } sb.append("####################\n"); } if (items[LOGCAT_LOG]) { sb.append(HEADER_SPLIT); sb.append("Logcat " + getString(R.string.log) + ":").append('\n'); //$NON-NLS-1$ try { Process proc = Runtime.getRuntime().exec("logcat -d -v time *:V"); //$NON-NLS-1$ readRawText(sb, proc.getInputStream()); } catch (Exception e) { Log.e(SiragonManager.class.getName(), e.getLocalizedMessage(), e); } sb.append("####################\n"); } return sb.toString(); }
From source file:org.uguess.android.sysinfo.SiragonManager.java
String generateHtmlReport(boolean[] items) { StringBuffer sb = new StringBuffer(); createHtmlHeader(getActivity(), sb, escapeHtml("Android System Report - " + new Date().toLocaleString())); //$NON-NLS-1$ if (items[BASIC_INFO]) { sb.append(openHeaderRow).append(getString(R.string.tab_infoCPU)).append(closeHeaderRow); sb.append(openRow).append(getString(R.string.sd_storage)).append(nextColumn4); String[] info = getExternalStorageInfo(); if (info == null) { sb.append(getString(R.string.info_not_available)); } else {/*from w w w . j ava2 s . co m*/ sb.append(getString(R.string.storage_summary, info[0], info[1])); } sb.append(closeRow); ///////////////////////////UCLIDES////////////////////////// sb.append(openHeaderRow).append(getString(R.string.tab_info)).append(closeHeaderRow); sb.append(openRow).append(getString(R.string.sd_storage)).append(nextColumn4); info = getExternalStorageInfo(); if (info == null) { sb.append(getString(R.string.info_not_available)); } else { sb.append(getString(R.string.storage_summary, info[0], info[1])); } sb.append(closeRow); /////////////////////////////////////////////////////////// sb.append(openRow).append(getString(R.string.a2sd_storage)).append(nextColumn4); info = getA2SDStorageInfo(); if (info == null) { sb.append(getString(R.string.info_not_available)); } else { sb.append(getString(R.string.storage_summary, info[0], info[1])); } sb.append(closeRow); sb.append(openRow).append(getString(R.string.internal_storage)).append(nextColumn4); info = getInternalStorageInfo(); if (info == null) { sb.append(getString(R.string.info_not_available)); } else { sb.append(getString(R.string.storage_summary, info[0], info[1])); } sb.append(closeRow); sb.append(openRow).append(getString(R.string.system_storage)).append(nextColumn4); info = getSystemStorageInfo(); if (info == null) { sb.append(getString(R.string.info_not_available)); } else { sb.append(getString(R.string.storage_summary, info[0], info[1])); } sb.append(closeRow); sb.append(openRow).append(getString(R.string.cache_storage)).append(nextColumn4); info = getCacheStorageInfo(); if (info == null) { sb.append(getString(R.string.info_not_available)); } else { sb.append(getString(R.string.storage_summary, info[0], info[1])); } sb.append(closeRow); sb.append(openRow).append(getString(R.string.memory)).append(nextColumn4); info = getMemInfo(); if (info == null) { sb.append(getString(R.string.info_not_available)); } else { sb.append(getString(R.string.storage_summary, info[0], info[2]) + getString(R.string.idle_info, info[1])); } sb.append(closeRow); sb.append(openRow).append(getString(R.string.processor)).append(nextColumn4) .append(escapeHtml(getCpuInfo())).append(closeRow); String nInfo = getNetAddressInfo(); sb.append(openRow).append(getString(R.string.net_address)).append(nextColumn4) .append(nInfo == null ? getString(R.string.info_not_available) : nInfo).append(closeRow); sb.append(emptyRow); try { File f = new File(F_SCALE_FREQ); if (f.exists()) { sb.append(openFullRow).append(getString(R.string.sc_freq)); readRawText(sb, new FileInputStream(f)); sb.append(closeRow); } else { sb.append(openFullRow).append(getString(R.string.no_sc_freq_info)).append(closeRow); } sb.append(emptyRow); f = new File(F_CPU_INFO); if (f.exists()) { readRawHTML(sb, new FileInputStream(f)); } else { sb.append(openFullRow).append(getString(R.string.no_cpu_info)).append(closeRow); } sb.append(emptyRow); f = new File(F_MEM_INFO); if (f.exists()) { readRawHTML(sb, new FileInputStream(f)); } else { sb.append(openFullRow).append(getString(R.string.no_mem_info)).append(closeRow); } sb.append(emptyRow); f = new File(F_MOUNT_INFO); if (f.exists()) { readRawHTML(sb, new FileInputStream(f)); } else { sb.append(openFullRow).append(getString(R.string.no_mount_info)).append(closeRow); } sb.append(emptyRow); } catch (Exception e) { Log.e(SiragonManager.class.getName(), e.getLocalizedMessage(), e); } } if (items[APPLICATIONS]) { sb.append(openHeaderRow).append(getString(R.string.tab_apps)).append(closeHeaderRow); sb.append(openTitleRow).append("<b>") //$NON-NLS-1$ .append(getString(R.string.pkg_name)).append("</b>") //$NON-NLS-1$ .append(nextColumn).append("<b>") //$NON-NLS-1$ .append(getString(R.string.version)).append("</b>") //$NON-NLS-1$ .append(nextColumn).append("<b>") //$NON-NLS-1$ .append(getString(R.string.app_label)).append("</b>") //$NON-NLS-1$ .append(nextColumn).append("<b>") //$NON-NLS-1$ .append(getString(R.string.flags)).append("</b>") //$NON-NLS-1$ .append(nextColumn).append("<b>") //$NON-NLS-1$ .append(getString(R.string.source)).append("</b>") //$NON-NLS-1$ .append(closeRow); PackageManager pm = getActivity().getPackageManager(); List<PackageInfo> pkgs = pm.getInstalledPackages(0); if (pkgs != null) { for (int i = 0, size = pkgs.size(); i < size; i++) { PackageInfo pkg = pkgs.get(i); sb.append(openRow).append(escapeHtml(pkg.packageName)).append(nextColumn) .append(escapeHtml(pkg.versionName)).append(" (") //$NON-NLS-1$ .append(pkg.versionCode).append(')'); if (pkg.applicationInfo != null) { sb.append(nextColumn).append(escapeHtml(pkg.applicationInfo.loadLabel(pm).toString())) .append(nextColumn).append(pkg.applicationInfo.flags).append(nextColumn) .append(escapeHtml(pkg.applicationInfo.sourceDir)); } sb.append(closeRow); } } sb.append(emptyRow); } if (items[PROCESSES]) { sb.append(openHeaderRow).append(getString(R.string.tab_procs)).append(closeHeaderRow); sb.append(openTitleRow).append("<b>") //$NON-NLS-1$ .append(getString(R.string.importance)).append("</b>") //$NON-NLS-1$ .append(nextColumn).append("<b>") //$NON-NLS-1$ .append(getString(R.string.pid)).append("</b>") //$NON-NLS-1$ .append(nextColumn).append("<b>") //$NON-NLS-1$ .append(getString(R.string.proc_name)).append("</b>") //$NON-NLS-1$ .append(nextColumn).append("<b>") //$NON-NLS-1$ .append(getString(R.string.app_label)).append("</b>") //$NON-NLS-1$ .append(closeRow); ActivityManager am = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE); List<RunningAppProcessInfo> procs = am.getRunningAppProcesses(); if (procs != null) { PackageManager pm = getActivity().getPackageManager(); for (int i = 0, size = procs.size(); i < size; i++) { RunningAppProcessInfo proc = procs.get(i); sb.append(openRow).append(getImportance(proc)).append(nextColumn).append(proc.pid) .append(nextColumn).append(escapeHtml(proc.processName)); try { ApplicationInfo ai = pm.getApplicationInfo(proc.processName, 0); if (ai != null) { CharSequence label = pm.getApplicationLabel(ai); if (label != null && !label.equals(proc.processName)) { sb.append(nextColumn).append(escapeHtml(label.toString())); } } } catch (NameNotFoundException e) { // ignore this error } sb.append(closeRow); } } sb.append(emptyRow); } if (items[NETSTATES]) { sb.append(openHeaderRow).append(getString(R.string.tab_netstat)).append(closeHeaderRow); try { readRawHTML(sb, new FileInputStream("/proc/net/tcp")); //$NON-NLS-1$ sb.append(emptyRow); readRawHTML(sb, new FileInputStream("/proc/net/udp")); //$NON-NLS-1$ } catch (Exception e) { Log.e(SiragonManager.class.getName(), e.getLocalizedMessage(), e); } sb.append(emptyRow); } if (items[DMESG_LOG]) { sb.append(openHeaderRow).append("Dmesg " //$NON-NLS-1$ + getString(R.string.log)).append(closeHeaderRow); try { Process proc = Runtime.getRuntime().exec("dmesg"); //$NON-NLS-1$ readRawHTML(sb, proc.getInputStream()); } catch (Exception e) { Log.e(SiragonManager.class.getName(), e.getLocalizedMessage(), e); } sb.append(emptyRow); } if (items[LOGCAT_LOG]) { sb.append(openHeaderRow).append("Logcat " //$NON-NLS-1$ + getString(R.string.log)).append(closeHeaderRow); try { Process proc = Runtime.getRuntime().exec("logcat -d -v time *:V"); //$NON-NLS-1$ readRawHTML(sb, proc.getInputStream()); } catch (Exception e) { Log.e(SiragonManager.class.getName(), e.getLocalizedMessage(), e); } sb.append(emptyRow); } sb.append("</table></font></body></html>"); //$NON-NLS-1$ return sb.toString(); }
From source file:com.codename1.impl.android.AndroidImplementation.java
/** * @inheritDoc/*from w ww. j a v a2s . co m*/ */ public String getProperty(String key, String defaultValue) { if (key.equalsIgnoreCase("cn1_push_prefix")) { /*if(!checkForPermission(Manifest.permission.READ_PHONE_STATE, "This is required to get notifications")){ return ""; }*/ boolean has = hasAndroidMarket(); if (has) { return "gcm"; } return defaultValue; } if ("OS".equals(key)) { return "Android"; } if ("androidId".equals(key)) { return Settings.Secure.getString(getContext().getContentResolver(), Settings.Secure.ANDROID_ID); } if ("cellId".equals(key)) { try { if (!checkForPermission(Manifest.permission.READ_PHONE_STATE, "This is required to get the cellId")) { return defaultValue; } String serviceName = Context.TELEPHONY_SERVICE; TelephonyManager telephonyManager = (TelephonyManager) getContext().getSystemService(serviceName); int cellId = ((GsmCellLocation) telephonyManager.getCellLocation()).getCid(); return "" + cellId; } catch (Throwable t) { return defaultValue; } } if ("AppName".equals(key)) { final PackageManager pm = getContext().getPackageManager(); ApplicationInfo ai; try { ai = pm.getApplicationInfo(getContext().getPackageName(), 0); } catch (NameNotFoundException e) { ai = null; } String applicationName = (String) (ai != null ? pm.getApplicationLabel(ai) : null); if (applicationName == null) { return defaultValue; } return applicationName; } if ("AppVersion".equals(key)) { try { PackageInfo i = getContext().getPackageManager() .getPackageInfo(getContext().getApplicationInfo().packageName, 0); return i.versionName; } catch (NameNotFoundException ex) { ex.printStackTrace(); } return defaultValue; } if ("Platform".equals(key)) { String p = System.getProperty("platform"); if (p == null) { return defaultValue; } return p; } if ("User-Agent".equals(key)) { String ua = getUserAgent(); if (ua == null) { return defaultValue; } return ua; } if ("OSVer".equals(key)) { return "" + android.os.Build.VERSION.RELEASE; } if ("DeviceName".equals(key)) { return "" + android.os.Build.MODEL; } try { if ("IMEI".equals(key) || "UDID".equals(key)) { if (!checkForPermission(Manifest.permission.READ_PHONE_STATE, "This is required to get the device ID")) { return ""; } TelephonyManager tm = (TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE); String imei = null; if (tm != null && tm.getDeviceId() != null) { // for phones or 3g tablets imei = tm.getDeviceId(); } else { try { imei = Secure.getString(getContext().getContentResolver(), Secure.ANDROID_ID); } catch (Throwable t) { com.codename1.io.Log.e(t); } } return imei; } if ("MSISDN".equals(key)) { if (!checkForPermission(Manifest.permission.READ_PHONE_STATE, "This is required to get the device ID")) { return ""; } TelephonyManager tm = (TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE); return tm.getLine1Number(); } } catch (Throwable t) { // will be caused by no permissions. return defaultValue; } if (getActivity() != null) { android.content.Intent intent = getActivity().getIntent(); if (intent != null) { Bundle extras = intent.getExtras(); if (extras != null) { String value = extras.getString(key); if (value != null) { return value; } } } } //these keys/values are from the Application Resources (strings values) try { int id = getContext().getResources().getIdentifier(key, "string", getContext().getApplicationInfo().packageName); if (id != 0) { String val = getContext().getResources().getString(id); return val; } } catch (Exception e) { } return System.getProperty(key, super.getProperty(key, defaultValue)); }