Example usage for android.os UserHandle myUserId

List of usage examples for android.os UserHandle myUserId

Introduction

In this page you can find the example usage for android.os UserHandle myUserId.

Prototype

@SystemApi
public static @UserIdInt int myUserId() 

Source Link

Document

Returns the user id of the current process

Usage

From source file:com.android.settings.HWSettings.java

public void updateHeaderList(List<Header> target) {
    final boolean showDev = mDevelopmentPreferences.getBoolean(DevelopmentSettings.PREF_SHOW,
            android.os.Build.TYPE.equals("eng"));
    int i = 0;// w w  w  .  j a  v a  2 s .co  m
    boolean IsSupVoice = this.getResources().getBoolean(com.android.internal.R.bool.config_voice_capable);
    final UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
    mHeaderIndexMap.clear();
    while (i < target.size()) {
        Header header = target.get(i);
        // Ids are integers, so downcasting
        int id = (int) header.id;
        if (id == R.id.operator_settings || id == R.id.manufacturer_settings) {
            Utils.updateHeaderToSpecificActivityFromMetaDataOrRemove(this, target, header);
        } else if (id == R.id.wifi_settings) {
            // Remove WiFi Settings if WiFi service is not available.
            if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI)) {
                target.remove(i);
            }
        } else if (id == R.id.bluetooth_settings) {
            // Remove Bluetooth Settings if Bluetooth service is not available.
            if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) {
                target.remove(i);
            }
        } else if (id == R.id.data_usage_settings) {
            // Remove data usage when kernel module not enabled
            final INetworkManagementService netManager = INetworkManagementService.Stub
                    .asInterface(ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE));
            try {
                /* SPRDADD to delete the data usage item of settings @{ */
                boolean support_cmcc = SystemProperties.get("ro.operator").equals("cmcc");
                if (!netManager.isBandwidthControlEnabled() || support_cmcc) {
                    target.remove(i);
                }
            } catch (RemoteException e) {
                // ignored
            }
        } else if (id == R.id.battery_settings) {
            // Remove battery settings when battery is not available. (e.g. TV)

            if (!mBatteryPresent) {
                target.remove(i);
            }
            /* @} */
        } else if (id == R.id.account_settings) {
            int headerIndex = i + 1;
            i = insertAccountsHeaders(target, headerIndex);
            // SPRD: clear viewCache
            ListAdapter listAdapter = getListAdapter();
            if (listAdapter instanceof HeaderAdapter) {
                // add for tab style
                ((HeaderAdapter) listAdapter).flushViewCache();
            }
        } else if (id == R.id.home_settings) {
            if (!updateHomeSettingHeaders(header)) {
                target.remove(i);
            }
        } else if (id == R.id.user_settings) {
            if (!UserHandle.MU_ENABLED || !UserManager.supportsMultipleUsers() || Utils.isMonkeyRunning()) {
                target.remove(i);
            }
        } else if (id == R.id.nfc_payment_settings) {
            if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)) {
                target.remove(i);
            } else {
                // Only show if NFC is on and we have the HCE feature
                NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
                if (!adapter.isEnabled() || !getPackageManager()
                        .hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)) {
                    target.remove(i);
                }
            }
        } else if (id == R.id.development_settings) {
            if (!showDev) {
                target.remove(i);
            }
        } else if (id == R.id.account_add) {
            if (um.hasUserRestriction(UserManager.DISALLOW_MODIFY_ACCOUNTS)) {
                target.remove(i);
            }
        }

        /* SPRD: modified for cucc feature @{ */
        else if (id == R.id.network_preference_settings) {
            //if (!("cucc".equals(WifiManager.SUPPORT_VERSION))) {
            if (!CU_SUPPORT) { //modify for CUCC support  2013-11-22
                target.remove(header);
            }
        }
        /* @} */
        /* SPRD: add AudioProfile  @{ */
        else if (id == R.id.sound_settings && IsSupVoice) {
            target.remove(header);
        } else if (id == R.id.audio_profiles && !IsSupVoice) {
            target.remove(header);
        }
        /* @} */
        /* SPRD: for multi-sim @{ */
        else if (id == R.id.dual_sim_settings) {
            if (!TelephonyManager.isMultiSim() || (!mVoiceCapable)) {
                target.remove(header);
            }
        }
        /* @} */
        /* SPRD: add for uui style 335009 @{ */
        else if (id == R.id.uninstall_settings) {
            target.remove(header);
        }
        /* @} */
        /*
        else if (id == R.id.mobile_network_settings_hw){
              header.intent.putExtra(MobileSimChoose.PACKAGE_NAME,
               "com.android.phone");
              header.intent.putExtra(MobileSimChoose.CLASS_NAME,
               "com.android.phone.MobileNetworkSettings");
        }
        */
        if (i < target.size() && target.get(i) == header && UserHandle.MU_ENABLED && UserHandle.myUserId() != 0
                && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, id)) {
            target.remove(i);
        }

        // Increment if the current one wasn't removed by the Utils code.
        if (i < target.size() && target.get(i) == header) {
            // Hold on to the first header, when we need to reset to the top-level
            if (mFirstHeader == null
                    && HeaderAdapter.getHeaderType(header) != HeaderAdapter.HEADER_TYPE_CATEGORY) {
                mFirstHeader = header;
            }
            mHeaderIndexMap.put(id, i);
            i++;
        }
    }
}

From source file:com.android.settings.applications.CanBeOnSdCardChecker.java

@Override
public void onClick(DialogInterface dialog, int which) {
    if (mResetDialog == dialog) {
        final PackageManager pm = getActivity().getPackageManager();
        final IPackageManager mIPm = IPackageManager.Stub.asInterface(ServiceManager.getService("package"));
        final INotificationManager nm = INotificationManager.Stub
                .asInterface(ServiceManager.getService(Context.NOTIFICATION_SERVICE));
        final NetworkPolicyManager npm = NetworkPolicyManager.from(getActivity());
        final AppOpsManager aom = (AppOpsManager) getActivity().getSystemService(Context.APP_OPS_SERVICE);
        final Handler handler = new Handler(getActivity().getMainLooper());
        (new AsyncTask<Void, Void, Void>() {
            @Override/*w w  w  .  jav  a 2  s.  c o  m*/
            protected Void doInBackground(Void... params) {
                List<ApplicationInfo> apps = pm
                        .getInstalledApplications(PackageManager.GET_DISABLED_COMPONENTS);
                for (int i = 0; i < apps.size(); i++) {
                    ApplicationInfo app = apps.get(i);
                    try {
                        if (DEBUG)
                            Log.v(TAG, "Enabling notifications: " + app.packageName);
                        nm.setNotificationsEnabledForPackage(app.packageName, app.uid, true);
                    } catch (android.os.RemoteException ex) {
                    }
                    if (!app.enabled) {
                        if (DEBUG)
                            Log.v(TAG, "Enabling app: " + app.packageName);
                        if (pm.getApplicationEnabledSetting(
                                app.packageName) == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) {
                            pm.setApplicationEnabledSetting(app.packageName,
                                    PackageManager.COMPONENT_ENABLED_STATE_DEFAULT,
                                    PackageManager.DONT_KILL_APP);
                        }
                    }
                }
                try {
                    mIPm.resetPreferredActivities(UserHandle.myUserId());
                } catch (RemoteException e) {
                }
                aom.resetAllModes();
                final int[] restrictedUids = npm.getUidsWithPolicy(POLICY_REJECT_METERED_BACKGROUND);
                final int currentUserId = ActivityManager.getCurrentUser();
                for (int uid : restrictedUids) {
                    // Only reset for current user
                    if (UserHandle.getUserId(uid) == currentUserId) {
                        if (DEBUG)
                            Log.v(TAG, "Clearing data policy: " + uid);
                        npm.setUidPolicy(uid, POLICY_NONE);
                    }
                }
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        if (DEBUG)
                            Log.v(TAG, "Done clearing");
                        if (getActivity() != null && mActivityResumed) {
                            if (DEBUG)
                                Log.v(TAG, "Updating UI!");
                            for (int i = 0; i < mTabs.size(); i++) {
                                TabInfo tab = mTabs.get(i);
                                if (tab.mApplications != null) {
                                    tab.mApplications.pause();
                                }
                            }
                            if (mCurTab != null) {
                                mCurTab.resume(mSortOrder);
                            }
                        }
                    }
                });
                return null;
            }
        }).execute();
    }
}

From source file:com.android.settings.HWSettings.java

@Override
public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
    // Override the fragment title for Wallpaper settings
    int titleRes = pref.getTitleRes();
    if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) {
        titleRes = R.string.wallpaper_settings_fragment_title;
    } else if (pref.getFragment().equals(OwnerInfoSettings.class.getName())
            && UserHandle.myUserId() != UserHandle.USER_OWNER) {
        if (UserManager.get(this).isLinkedUser()) {
            titleRes = R.string.profile_info_settings_title;
        } else {//from ww w  .  j a  v  a  2  s  .c om
            titleRes = R.string.user_info_settings_title;
        }
    }
    startPreferencePanel(pref.getFragment(), pref.getExtras(), titleRes, pref.getTitle(), null, 0);
    return true;
}

From source file:android.app.Activity.java

/**
 * Create a new PendingIntent object which you can hand to others 
 * for them to use to send result data back to your 
 * {@link #onActivityResult} callback.  The created object will be either 
 * one-shot (becoming invalid after a result is sent back) or multiple 
 * (allowing any number of results to be sent through it). 
 *  //  www  .  j  a  v  a 2s. c o  m
 * @param requestCode Private request code for the sender that will be
 * associated with the result data when it is returned.  The sender can not
 * modify this value, allowing you to identify incoming results.
 * @param data Default data to supply in the result, which may be modified
 * by the sender.
 * @param flags May be {@link PendingIntent#FLAG_ONE_SHOT PendingIntent.FLAG_ONE_SHOT},
 * {@link PendingIntent#FLAG_NO_CREATE PendingIntent.FLAG_NO_CREATE},
 * {@link PendingIntent#FLAG_CANCEL_CURRENT PendingIntent.FLAG_CANCEL_CURRENT},
 * {@link PendingIntent#FLAG_UPDATE_CURRENT PendingIntent.FLAG_UPDATE_CURRENT},
 * or any of the flags as supported by
 * {@link Intent#fillIn Intent.fillIn()} to control which unspecified parts
 * of the intent that can be supplied when the actual send happens.
 * 
 * @return Returns an existing or new PendingIntent matching the given
 * parameters.  May return null only if
 * {@link PendingIntent#FLAG_NO_CREATE PendingIntent.FLAG_NO_CREATE} has been
 * supplied.
 * 
 * @see PendingIntent
 */
public PendingIntent createPendingResult(int requestCode, Intent data, int flags) {
    String packageName = getPackageName();
    try {
        data.prepareToLeaveProcess();
        IIntentSender target = ActivityManagerNative.getDefault().getIntentSender(
                ActivityManager.INTENT_SENDER_ACTIVITY_RESULT, packageName,
                mParent == null ? mToken : mParent.mToken, mEmbeddedID, requestCode, new Intent[] { data },
                null, flags, null, UserHandle.myUserId());
        return target != null ? new PendingIntent(target) : null;
    } catch (RemoteException e) {
        // Empty
    }
    return null;
}