Java Code Examples for android.os.SystemProperties#getBoolean()

The following examples show how to use android.os.SystemProperties#getBoolean() . 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: RecentTasks.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Loads the parameters from the system resources.
 */
@VisibleForTesting
void loadParametersFromResources(Resources res) {
    if (ActivityManager.isLowRamDeviceStatic()) {
        mMinNumVisibleTasks = res.getInteger(
                com.android.internal.R.integer.config_minNumVisibleRecentTasks_lowRam);
        mMaxNumVisibleTasks = res.getInteger(
                com.android.internal.R.integer.config_maxNumVisibleRecentTasks_lowRam);
    } else if (SystemProperties.getBoolean("ro.recents.grid", false)) {
        mMinNumVisibleTasks = res.getInteger(
                com.android.internal.R.integer.config_minNumVisibleRecentTasks_grid);
        mMaxNumVisibleTasks = res.getInteger(
                com.android.internal.R.integer.config_maxNumVisibleRecentTasks_grid);
    } else {
        mMinNumVisibleTasks = res.getInteger(
                com.android.internal.R.integer.config_minNumVisibleRecentTasks);
        mMaxNumVisibleTasks = res.getInteger(
                com.android.internal.R.integer.config_maxNumVisibleRecentTasks);
    }
    final int sessionDurationHrs = res.getInteger(
            com.android.internal.R.integer.config_activeTaskDurationHours);
    mActiveTasksSessionDurationMs = (sessionDurationHrs > 0)
            ? TimeUnit.HOURS.toMillis(sessionDurationHrs)
            : -1;
}
 
Example 2
Source File: FallbackCategoryProvider.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
public static void loadFallbacks() {
    sFallbacks.clear();
    if (SystemProperties.getBoolean("fw.ignore_fb_categories", false)) {
        Log.d(TAG, "Ignoring fallback categories");
        return;
    }

    final AssetManager assets = new AssetManager();
    assets.addAssetPath("/system/framework/framework-res.apk");
    final Resources res = new Resources(assets, null, null);

    try (BufferedReader reader = new BufferedReader(new InputStreamReader(
            res.openRawResource(com.android.internal.R.raw.fallback_categories)))) {
        String line;
        while ((line = reader.readLine()) != null) {
            if (line.charAt(0) == '#') continue;
            final String[] split = line.split(",");
            if (split.length == 2) {
                sFallbacks.put(split[0], Integer.parseInt(split[1]));
            }
        }
        Log.d(TAG, "Found " + sFallbacks.size() + " fallback categories");
    } catch (IOException | NumberFormatException e) {
        Log.w(TAG, "Failed to read fallback categories", e);
    }
}
 
Example 3
Source File: DisplayManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
DisplayManagerService(Context context, Injector injector) {
    super(context);
    mInjector = injector;
    mContext = context;
    mHandler = new DisplayManagerHandler(DisplayThread.get().getLooper());
    mUiHandler = UiThread.getHandler();
    mDisplayAdapterListener = new DisplayAdapterListener();
    mSingleDisplayDemoMode = SystemProperties.getBoolean("persist.demo.singledisplay", false);
    Resources resources = mContext.getResources();
    mDefaultDisplayDefaultColorMode = mContext.getResources().getInteger(
            com.android.internal.R.integer.config_defaultDisplayDefaultColorMode);
    mDefaultDisplayTopInset = SystemProperties.getInt(PROP_DEFAULT_DISPLAY_TOP_INSET, -1);
    float[] lux = getFloatArray(resources.obtainTypedArray(
            com.android.internal.R.array.config_minimumBrightnessCurveLux));
    float[] nits = getFloatArray(resources.obtainTypedArray(
            com.android.internal.R.array.config_minimumBrightnessCurveNits));
    mMinimumBrightnessCurve = new Curve(lux, nits);
    mMinimumBrightnessSpline = Spline.createSpline(lux, nits);

    PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
    mGlobalDisplayBrightness = pm.getDefaultScreenBrightnessSetting();
    mCurrentUserId = UserHandle.USER_SYSTEM;

    mSystemReady = false;
}
 
Example 4
Source File: ContentService.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
private SyncManager getSyncManager() {
    if (SystemProperties.getBoolean("config.disable_network", false)) {
        return null;
    }

    synchronized(mSyncManagerLock) {
        try {
            // Try to create the SyncManager, return null if it fails (e.g. the disk is full).
            if (mSyncManager == null) mSyncManager = new SyncManager(mContext, mFactoryTest);
        } catch (SQLiteException e) {
            Log.e(TAG, "Can't create SyncManager", e);
        }
        return mSyncManager;
    }
}
 
Example 5
Source File: BinderCallsStatsService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public static void start() {
    BinderCallsStatsService service = new BinderCallsStatsService();
    ServiceManager.addService("binder_calls_stats", service);
    boolean detailedTrackingEnabled = SystemProperties.getBoolean(
            PERSIST_SYS_BINDER_CALLS_DETAILED_TRACKING, false);

    if (detailedTrackingEnabled) {
        Slog.i(TAG, "Enabled CPU usage tracking for binder calls. Controlled by "
                + PERSIST_SYS_BINDER_CALLS_DETAILED_TRACKING
                + " or via dumpsys binder_calls_stats --enable-detailed-tracking");
        BinderCallsStats.getInstance().setDetailedTracking(true);
    }
}
 
Example 6
Source File: LoadedApk.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void setupJitProfileSupport() {
    if (!SystemProperties.getBoolean("dalvik.vm.usejitprofiles", false)) {
        return;
    }
    // Only set up profile support if the loaded apk has the same uid as the
    // current process.
    // Currently, we do not support profiling across different apps.
    // (e.g. application's uid might be different when the code is
    // loaded by another app via createApplicationContext)
    if (mApplicationInfo.uid != Process.myUid()) {
        return;
    }

    final List<String> codePaths = new ArrayList<>();
    if ((mApplicationInfo.flags & ApplicationInfo.FLAG_HAS_CODE) != 0) {
        codePaths.add(mApplicationInfo.sourceDir);
    }
    if (mApplicationInfo.splitSourceDirs != null) {
        Collections.addAll(codePaths, mApplicationInfo.splitSourceDirs);
    }

    if (codePaths.isEmpty()) {
        // If there are no code paths there's no need to setup a profile file and register with
        // the runtime,
        return;
    }

    for (int i = codePaths.size() - 1; i >= 0; i--) {
        String splitName = i == 0 ? null : mApplicationInfo.splitNames[i - 1];
        String profileFile = ArtManager.getCurrentProfilePath(
                mPackageName, UserHandle.myUserId(), splitName);
        VMRuntime.registerAppInfo(profileFile, new String[] {codePaths.get(i)});
    }

    // Register the app data directory with the reporter. It will
    // help deciding whether or not a dex file is the primary apk or a
    // secondary dex.
    DexLoadReporter.getInstance().registerAppDataDir(mPackageName, mDataDir);
}
 
Example 7
Source File: ZygoteInit.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private static void preloadOpenGL() {
    String driverPackageName = SystemProperties.get(PROPERTY_GFX_DRIVER);
    if (!SystemProperties.getBoolean(PROPERTY_DISABLE_OPENGL_PRELOADING, false) &&
            (driverPackageName == null || driverPackageName.isEmpty())) {
        EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);
    }
}
 
Example 8
Source File: DexLoadReporter.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void registerSecondaryDexForProfiling(String[] dexPaths) {
    if (!SystemProperties.getBoolean("dalvik.vm.dexopt.secondary", false)) {
        return;
    }
    // Make a copy of the current data directories so that we don't keep the lock
    // while registering for profiling. The registration will perform I/O to
    // check for or create the profile.
    String[] dataDirs;
    synchronized (mDataDirs) {
        dataDirs = mDataDirs.toArray(new String[0]);
    }
    for (String dexPath : dexPaths) {
        registerSecondaryDexForProfiling(dexPath, dataDirs);
    }
}
 
Example 9
Source File: VrManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void onStart() {
    synchronized(mLock) {
        initializeNative();
        mContext = getContext();
    }

    mBootsToVr = SystemProperties.getBoolean("ro.boot.vr", false);
    mUseStandbyToExitVrMode = mBootsToVr
            && SystemProperties.getBoolean("persist.vr.use_standby_to_exit_vr_mode", true);
    publishLocalService(VrManagerInternal.class, new LocalService());
    publishBinderService(Context.VR_SERVICE, mVrManager.asBinder());
}
 
Example 10
Source File: RescueParty.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private static boolean isDisabled() {
    // Check if we're explicitly enabled for testing
    if (SystemProperties.getBoolean(PROP_ENABLE_RESCUE, false)) {
        return false;
    }

    // We're disabled on all engineering devices
    if (Build.IS_ENG) {
        Slog.v(TAG, "Disabled because of eng build");
        return true;
    }

    // We're disabled on userdebug devices connected over USB, since that's
    // a decent signal that someone is actively trying to debug the device,
    // or that it's in a lab environment.
    if (Build.IS_USERDEBUG && isUsbActive()) {
        Slog.v(TAG, "Disabled because of active USB connection");
        return true;
    }

    // One last-ditch check
    if (SystemProperties.getBoolean(PROP_DISABLE_RESCUE, false)) {
        Slog.v(TAG, "Disabled because of manual property");
        return true;
    }

    return false;
}
 
Example 11
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
private boolean isBuggy() {
    // STOPSHIP: fix buggy apps
    if (SystemProperties.getBoolean("fw.ignore_buggy", false)) return false;
    if ("com.google.android.tts".equals(getApplicationInfo().packageName)) return true;
    if ("com.breel.geswallpapers".equals(getApplicationInfo().packageName)) return true;
    return false;
}
 
Example 12
Source File: StorageManagerService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public StorageVolume[] getVolumeList(int uid, String packageName, int flags) {
    final int userId = UserHandle.getUserId(uid);

    final boolean forWrite = (flags & StorageManager.FLAG_FOR_WRITE) != 0;
    final boolean realState = (flags & StorageManager.FLAG_REAL_STATE) != 0;
    final boolean includeInvisible = (flags & StorageManager.FLAG_INCLUDE_INVISIBLE) != 0;

    final boolean userKeyUnlocked;
    final boolean storagePermission;
    final long token = Binder.clearCallingIdentity();
    try {
        userKeyUnlocked = isUserKeyUnlocked(userId);
        storagePermission = mStorageManagerInternal.hasExternalStorage(uid, packageName);
    } finally {
        Binder.restoreCallingIdentity(token);
    }

    boolean foundPrimary = false;

    final ArrayList<StorageVolume> res = new ArrayList<>();
    synchronized (mLock) {
        for (int i = 0; i < mVolumes.size(); i++) {
            final VolumeInfo vol = mVolumes.valueAt(i);
            switch (vol.getType()) {
                case VolumeInfo.TYPE_PUBLIC:
                case VolumeInfo.TYPE_EMULATED:
                    break;
                default:
                    continue;
            }

            boolean match = false;
            if (forWrite) {
                match = vol.isVisibleForWrite(userId);
            } else {
                match = vol.isVisibleForRead(userId)
                        || (includeInvisible && vol.getPath() != null);
            }
            if (!match) continue;

            boolean reportUnmounted = false;
            if ((vol.getType() == VolumeInfo.TYPE_EMULATED) && !userKeyUnlocked) {
                reportUnmounted = true;
            } else if (!storagePermission && !realState) {
                reportUnmounted = true;
            }

            final StorageVolume userVol = vol.buildStorageVolume(mContext, userId,
                    reportUnmounted);
            if (vol.isPrimary()) {
                res.add(0, userVol);
                foundPrimary = true;
            } else {
                res.add(userVol);
            }
        }
    }

    if (!foundPrimary) {
        Log.w(TAG, "No primary storage defined yet; hacking together a stub");

        final boolean primaryPhysical = SystemProperties.getBoolean(
                StorageManager.PROP_PRIMARY_PHYSICAL, false);

        final String id = "stub_primary";
        final File path = Environment.getLegacyExternalStorageDirectory();
        final String description = mContext.getString(android.R.string.unknownName);
        final boolean primary = true;
        final boolean removable = primaryPhysical;
        final boolean emulated = !primaryPhysical;
        final boolean allowMassStorage = false;
        final long maxFileSize = 0L;
        final UserHandle owner = new UserHandle(userId);
        final String uuid = null;
        final String state = Environment.MEDIA_REMOVED;

        res.add(0, new StorageVolume(id, path, path,
                description, primary, removable, emulated,
                allowMassStorage, maxFileSize, owner, uuid, state));
    }

    return res.toArray(new StorageVolume[res.size()]);
}
 
Example 13
Source File: FileUpdater.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
boolean injectShouldSkipWrite() {
    return SystemProperties.getBoolean(PROP_SKIP_WRITE, false);
}
 
Example 14
Source File: StorageManager.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/** {@hide} */
public static boolean hasAdoptable() {
    return SystemProperties.getBoolean(PROP_HAS_ADOPTABLE, false);
}
 
Example 15
Source File: ActivityManager.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
/**
 * Returns "true" if device is running in a test harness.
 */
public static boolean isRunningInTestHarness() {
    return SystemProperties.getBoolean("ro.test_harness", false);
}
 
Example 16
Source File: BackgroundDexOptService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private static boolean isBackgroundDexoptDisabled() {
    return SystemProperties.getBoolean("pm.dexopt.disable_bg_dexopt" /* key */,
            false /* default */);
}
 
Example 17
Source File: SurfaceTextureRenderer.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Set a collection of output {@link Surface}s that can be drawn to.
 *
 * @param surfaces a {@link Collection} of surfaces.
 */
public void configureSurfaces(Collection<Pair<Surface, Size>> surfaces) {
    releaseEGLContext();

    if (surfaces == null || surfaces.size() == 0) {
        Log.w(TAG, "No output surfaces configured for GL drawing.");
        return;
    }

    for (Pair<Surface, Size> p : surfaces) {
        Surface s = p.first;
        Size surfaceSize = p.second;
        // If pixel conversions aren't handled by egl, use a pbuffer
        try {
            EGLSurfaceHolder holder = new EGLSurfaceHolder();
            holder.surface = s;
            holder.width = surfaceSize.getWidth();
            holder.height = surfaceSize.getHeight();
            if (LegacyCameraDevice.needsConversion(s)) {
                mConversionSurfaces.add(holder);
                // LegacyCameraDevice is the producer of surfaces if it's not handled by EGL,
                // so LegacyCameraDevice needs to connect to the surfaces.
                LegacyCameraDevice.connectSurface(s);
            } else {
                mSurfaces.add(holder);
            }
        } catch (LegacyExceptionUtils.BufferQueueAbandonedException e) {
            Log.w(TAG, "Surface abandoned, skipping configuration... ", e);
        }
    }

    // Set up egl display
    configureEGLContext();

    // Set up regular egl surfaces if needed
    if (mSurfaces.size() > 0) {
        configureEGLOutputSurfaces(mSurfaces);
    }

    // Set up pbuffer surface if needed
    if (mConversionSurfaces.size() > 0) {
        configureEGLPbufferSurfaces(mConversionSurfaces);
    }
    makeCurrent((mSurfaces.size() > 0) ? mSurfaces.get(0).eglSurface :
            mConversionSurfaces.get(0).eglSurface);
    initializeGLState();
    mSurfaceTexture = new SurfaceTexture(getTextureId());

    // Set up performance tracking if enabled
    if (SystemProperties.getBoolean(LEGACY_PERF_PROPERTY, false)) {
        setupGlTiming();
    }
}
 
Example 18
Source File: ZygoteInit.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Finish remaining work for the newly forked system server process.
 */
private static Runnable handleSystemServerProcess(ZygoteConnection.Arguments parsedArgs) {
    // set umask to 0077 so new files and directories will default to owner-only permissions.
    // umask一般是用在你初始创建一个目录或者文件的时候赋予他们的权限
    Os.umask(S_IRWXG | S_IRWXO);

    // 设置当前进程名为 "system_server"
    if (parsedArgs.niceName != null) { 
        Process.setArgV0(parsedArgs.niceName);
    }

    final String systemServerClasspath = Os.getenv("SYSTEMSERVERCLASSPATH");
    if (systemServerClasspath != null) {
        // dex 优化操作
        performSystemServerDexOpt(systemServerClasspath);
        // Capturing profiles is only supported for debug or eng builds since selinux normally
        // prevents it.
        boolean profileSystemServer = SystemProperties.getBoolean(
                "dalvik.vm.profilesystemserver", false);
        if (profileSystemServer && (Build.IS_USERDEBUG || Build.IS_ENG)) {
            try {
                prepareSystemServerProfile(systemServerClasspath);
            } catch (Exception e) {
                Log.wtf(TAG, "Failed to set up system server profile", e);
            }
        }
    }

    if (parsedArgs.invokeWith != null) { // invokeWith 一般为空
        String[] args = parsedArgs.remainingArgs;
        // If we have a non-null system server class path, we'll have to duplicate the
        // existing arguments and append the classpath to it. ART will handle the classpath
        // correctly when we exec a new process.
        if (systemServerClasspath != null) {
            String[] amendedArgs = new String[args.length + 2];
            amendedArgs[0] = "-cp";
            amendedArgs[1] = systemServerClasspath;
            System.arraycopy(args, 0, amendedArgs, 2, args.length);
            args = amendedArgs;
        }

        WrapperInit.execApplication(parsedArgs.invokeWith,
                parsedArgs.niceName, parsedArgs.targetSdkVersion,
                VMRuntime.getCurrentInstructionSet(), null, args);

        throw new IllegalStateException("Unexpected return from WrapperInit.execApplication");
    } else {
        ClassLoader cl = null;
        if (systemServerClasspath != null) {
            // 创建类加载器,并赋给当前线程
            cl = createPathClassLoader(systemServerClasspath, parsedArgs.targetSdkVersion);
            
            Thread.currentThread().setContextClassLoader(cl);
        }

        /*
         * Pass the remaining arguments to SystemServer.
         */
        return ZygoteInit.zygoteInit(parsedArgs.targetSdkVersion, parsedArgs.remainingArgs, cl);
    }

    /* should never reach here */
}
 
Example 19
Source File: MockableSystemProperties.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public boolean getBoolean(String key, boolean def) {
    return SystemProperties.getBoolean(key, def);
}
 
Example 20
Source File: TextUtils.java    From android_9.0.0_r45 with Apache License 2.0 3 votes vote down vote up
/**
 * Return the layout direction for a given Locale
 *
 * @param locale the Locale for which we want the layout direction. Can be null.
 * @return the layout direction. This may be one of:
 * {@link android.view.View#LAYOUT_DIRECTION_LTR} or
 * {@link android.view.View#LAYOUT_DIRECTION_RTL}.
 *
 * Be careful: this code will need to be updated when vertical scripts will be supported
 */
public static int getLayoutDirectionFromLocale(Locale locale) {
    return ((locale != null && !locale.equals(Locale.ROOT)
                    && ULocale.forLocale(locale).isRightToLeft())
            // If forcing into RTL layout mode, return RTL as default
            || SystemProperties.getBoolean(Settings.Global.DEVELOPMENT_FORCE_RTL, false))
        ? View.LAYOUT_DIRECTION_RTL
        : View.LAYOUT_DIRECTION_LTR;
}