List of usage examples for android.content ComponentName getPackageName
public @NonNull String getPackageName()
From source file:net.grayswander.rotationmanager.RotationManagerService.java
@Override public void onAccessibilityEvent(AccessibilityEvent event) { if (event == null) { debug("Null event"); return;// ww w .j a va2 s. c om } if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) { String package_name; String class_name; try { package_name = event.getPackageName().toString(); class_name = event.getClassName().toString(); } catch (Exception e) { debug("Unable to get component"); return; } ComponentName componentName = new ComponentName(package_name, class_name); Log.d("Service", "Package: " + componentName.getPackageName() + " Class: " + componentName.getClassName()); ActivityInfo activityInfo = tryGetActivity(componentName); boolean isActivity = activityInfo != null; if (!isActivity) { debug("Received event with NULL activity."); return; } debug("Received app " + package_name); if (package_name.equals(this.currentPackage)) { debug("App has not been changed"); return; } debug("App has been changed"); boolean is_rotation_enabled = this.getAutoOrientationEnabled(); debug("Rotation: " + is_rotation_enabled); if (!appStartedFullScreen) { Log.d("Service", "Saving rotation settings, as fullscreen hack is inactive"); if (is_rotation_enabled != this.lastSetRotation) { debug("Setting rotation " + is_rotation_enabled + " for " + this.currentPackage); this.configuration.setRotationSetting(this.currentPackage, is_rotation_enabled); } } else { Log.d("Service", "Not saving rotation settings, as fullscreen hack is active"); } this.appStartedFullScreen = false; if (this.configuration.isForFullscreenWatcher(package_name)) { this.startFullscreenWatcher(); } else { if (this.configuration.isForFullscreenWatcher(this.currentPackage)) { this.stopFullscreenWatcher(); } } this.currentPackage = package_name; boolean app_rotation_setting = this.getAppRotationSetting(componentName); debug("Got rotation " + app_rotation_setting + " for " + package_name); if (is_rotation_enabled != app_rotation_setting) { debug("Setting rotation " + app_rotation_setting); this.setAutoOrientationEnabled(app_rotation_setting); } } }
From source file:edu.umich.flowfence.sandbox.SandboxContext.java
@Override public boolean bindService(Intent service, ServiceConnection conn, int flags) { ComponentName component = service.getComponent(); if (component != null && component.getPackageName().equals(BuildConfig.APPLICATION_ID) && component.getClassName().equals(FlowfenceService.class.getName())) { IBinder rootBinder = mRootService.asBinder(); ComponentName oldMapping;/*from w ww . j a v a2s .c om*/ synchronized (mBoundServices) { oldMapping = mBoundServices.put(conn, component); } if (oldMapping == null) { conn.onServiceConnected(component, rootBinder); } return true; } return super.bindService(service, conn, flags); }
From source file:org.opensilk.music.ui3.main.LibraryProviderInfoLoader.java
public Observable<LibraryProviderInfo> makeObservable() { return Observable.create(new Observable.OnSubscribe<List<ProviderInfo>>() { @Override/* w w w .j a va 2 s . co m*/ public void call(Subscriber<? super List<ProviderInfo>> subscriber) { final PackageManager pm = context.getPackageManager(); final List<ProviderInfo> providerInfos = pm.queryContentProviders(null, 0, PackageManager.GET_META_DATA); subscriber.onNext(providerInfos); subscriber.onCompleted(); } }).flatMap(new Func1<List<ProviderInfo>, Observable<ProviderInfo>>() { @Override public Observable<ProviderInfo> call(List<ProviderInfo> providerInfos) { return Observable.from(providerInfos); } }).filter(new Func1<ProviderInfo, Boolean>() { @Override public Boolean call(ProviderInfo providerInfo) { return StringUtils.startsWith(providerInfo.authority, LibraryProvider.AUTHORITY_PFX) //Ignore non exported providers unless they're ours && (StringUtils.equals(providerInfo.packageName, context.getPackageName()) || providerInfo.exported); } }).map(new Func1<ProviderInfo, LibraryProviderInfo>() { @Override public LibraryProviderInfo call(ProviderInfo providerInfo) { final PackageManager pm = context.getPackageManager(); final String authority = providerInfo.authority; final CharSequence title = providerInfo.loadLabel(pm); final ComponentName cn = new ComponentName(providerInfo.packageName, providerInfo.name); final Drawable icon = providerInfo.loadIcon(pm); CharSequence description; try { Context packageContext = context.createPackageContext(cn.getPackageName(), 0); Resources packageRes = packageContext.getResources(); description = packageRes.getString(providerInfo.descriptionRes); } catch (PackageManager.NameNotFoundException e) { description = ""; } final LibraryProviderInfo lpi = new LibraryProviderInfo(title.toString(), description.toString(), authority); lpi.icon = icon; for (String a : settings.readDisabledPlugins()) { if (a.equals(lpi.authority)) { lpi.isActive = false; break; } } return lpi; } }); }
From source file:org.opensilk.music.ui2.loader.PluginLoader.java
private PluginInfo readResolveInfo(PackageManager pm, List<ComponentName> disabledPlugins, ResolveInfo resolveInfo) {/* w w w . j a v a 2 s . c o m*/ boolean hasPermission = false; final String permission = resolveInfo.serviceInfo.permission; if (TextUtils.equals(permission, OrpheusApi.PERMISSION_BIND_LIBRARY_SERVICE) || TextUtils.equals(permission, "org.opensilk.music.debug.api.permission.BIND_LIBRARY_SERVICE")) { hasPermission = true; } final CharSequence title = resolveInfo.loadLabel(pm); final ComponentName cn = getComponentName(resolveInfo); final Drawable icon = resolveInfo.loadIcon(pm); CharSequence description; try { Context packageContext = context.createPackageContext(cn.getPackageName(), 0); Resources packageRes = packageContext.getResources(); description = packageRes.getString(resolveInfo.serviceInfo.descriptionRes); } catch (PackageManager.NameNotFoundException e) { description = null; } PluginInfo pluginInfo = new PluginInfo(title, description, cn); pluginInfo.hasPermission = hasPermission; pluginInfo.icon = icon; for (ComponentName c : disabledPlugins) { if (c.equals(pluginInfo.componentName)) { pluginInfo.isActive = false; break; } } return pluginInfo; }
From source file:com.hellofyc.base.app.AppSupportDelegate.java
public void startFragmentForResult(@NonNull Intent intent, int requestCode, @Nullable Bundle options) { ComponentName componentName = intent.getComponent(); String targetFragmentClassName = componentName.getClassName(); intent.setComponent(//from w ww. ja va2 s .c om new ComponentName(componentName.getPackageName(), SingleFragmentActivity.class.getName())); intent.putExtra(SingleFragmentActivity.EXTRA_FRAGMENT_CLASSNAME, targetFragmentClassName); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { mActivity.startActivityForResult(intent, requestCode, options); } else { mActivity.startActivityForResult(intent, requestCode); } }
From source file:com.openerp.services.MessageSyncService.java
/** * Perform sync.//from w ww.j a va 2 s . co m * * @param context the context * @param account the account * @param extras the extras * @param authority the authority * @param provider the provider * @param syncResult the sync result */ public void performSync(Context context, Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { Intent intent = new Intent(); Intent updateWidgetIntent = new Intent(); updateWidgetIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE); updateWidgetIntent.putExtra(MessageWidget.ACTION_MESSAGE_WIDGET_UPDATE, true); intent.setAction(SyncFinishReceiver.SYNC_FINISH); OEUser user = OpenERPAccountManager.getAccountDetail(context, account.name); try { MessageDB msgDb = new MessageDB(context); msgDb.setAccountUser(user); OEHelper oe = msgDb.getOEInstance(); if (oe == null) { return; } int user_id = user.getUser_id(); // Updating User Context for OE-JSON-RPC JSONObject newContext = new JSONObject(); newContext.put("default_model", "res.users"); newContext.put("default_res_id", user_id); OEArguments arguments = new OEArguments(); // Param 1 : ids arguments.addNull(); // Param 2 : domain OEDomain domain = new OEDomain(); // Data limit. PreferenceManager mPref = new PreferenceManager(context); int data_limit = mPref.getInt("sync_data_limit", 60); domain.add("create_date", ">=", OEDate.getDateBefore(data_limit)); if (!extras.containsKey("group_ids")) { // Last id JSONArray msgIds = new JSONArray(); for (OEDataRow row : msgDb.select()) { msgIds.put(row.getInt("id")); } domain.add("id", "not in", msgIds); domain.add("|"); // Argument for check partner_ids.user_id is current user domain.add("partner_ids.user_ids", "in", new JSONArray().put(user_id)); domain.add("|"); // Argument for check notification_ids.partner_ids.user_id // is // current user domain.add("notification_ids.partner_id.user_ids", "in", new JSONArray().put(user_id)); // Argument for check author id is current user domain.add("author_id.user_ids", "in", new JSONArray().put(user_id)); } else { JSONArray group_ids = new JSONArray(extras.getString("group_ids")); // Argument for group model check domain.add("model", "=", "mail.group"); // Argument for group model res id domain.add("res_id", "in", group_ids); } arguments.add(domain.getArray()); // Param 3 : message_unload_ids arguments.add(new JSONArray()); // Param 4 : thread_level arguments.add(true); // Param 5 : context arguments.add(oe.updateContext(newContext)); // Param 6 : parent_id arguments.addNull(); // Param 7 : limit arguments.add(50); List<Integer> ids = msgDb.ids(); if (oe.syncWithMethod("message_read", arguments)) { int affected_rows = oe.getAffectedRows(); List<Integer> affected_ids = oe.getAffectedIds(); boolean notification = true; ActivityManager am = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1); ComponentName componentInfo = taskInfo.get(0).topActivity; if (componentInfo.getPackageName().equalsIgnoreCase("com.openerp")) { notification = false; } if (notification && affected_rows > 0) { OENotificationHelper mNotification = new OENotificationHelper(); Intent mainActiivty = new Intent(context, MainActivity.class); mNotification.setResultIntent(mainActiivty, context); String notify_title = context.getResources().getString(R.string.messages_sync_notify_title); notify_title = String.format(notify_title, affected_rows); String notify_body = context.getResources().getString(R.string.messages_sync_notify_body); notify_body = String.format(notify_body, affected_rows); mNotification.showNotification(context, notify_title, notify_body, authority, R.drawable.ic_oe_notification); } intent.putIntegerArrayListExtra("new_ids", (ArrayList<Integer>) affected_ids); } List<Integer> updated_ids = updateOldMessages(msgDb, oe, user, ids); intent.putIntegerArrayListExtra("updated_ids", (ArrayList<Integer>) updated_ids); } catch (Exception e) { e.printStackTrace(); } if (user.getAndroidName().equals(account.name)) { context.sendBroadcast(intent); context.sendBroadcast(updateWidgetIntent); } }
From source file:cn.sharesdk.analysis.server.ServiceHelper.java
public boolean isAppExit() { if (context == null) { Ln.e("getActivityName", "context is null that do not get the package's name "); return true; }//from ww w . ja v a 2s . c om String packageName = context.getPackageName(); ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); if (deviceHelper.checkPermissions("android.permission.GET_TASKS")) { ComponentName cn = am.getRunningTasks(1).get(0).topActivity; boolean isEqual = packageName.equals(cn.getPackageName()); return !isEqual; } else { Ln.e("lost permission", "android.permission.GET_TASKS"); return true; } }
From source file:org.openmidaas.app.activities.AuthorizationActivity.java
public boolean isApplicationSentToBackground(final Context context) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> tasks = am.getRunningTasks(1); if (!tasks.isEmpty()) { ComponentName topActivity = tasks.get(0).topActivity; if (!topActivity.getPackageName().equals(context.getPackageName())) { return true; }/*from www . j a va2 s. c o m*/ } return false; }
From source file:com.luongbui.andersenfestival.muzei.AndersenFestivalSource.java
@Override protected void onSubscriberRemoved(ComponentName subscriber) { super.onSubscriberRemoved(subscriber); //android.util.Log.d("onSubscriberRemoved()", "onSubscriberRemoved()"); // Remove the subscriber. Set<String> subs = prefs.getStringSet(SUBS_KEY, new TreeSet<String>()); subs.remove(subscriber.getPackageName()); saveSubsPrefs(subs);/*from www.j av a 2s . co m*/ }
From source file:arun.com.chromer.settings.widgets.AppPreferenceCardView.java
public void updatePreference(@Nullable final ComponentName componentName) { final String flatComponent = componentName == null ? null : componentName.flattenToString(); switch (preferenceType) { case CUSTOM_TAB_PROVIDER: if (componentName != null) { Preferences.get(getContext()).customTabPackage(componentName.getPackageName()); }//from w ww . j a va 2 s . co m break; case SECONDARY_BROWSER: Preferences.get(getContext()).secondaryBrowserComponent(flatComponent); break; case FAVORITE_SHARE: Preferences.get(getContext()).favShareComponent(flatComponent); break; } refreshState(); }