Java Code Examples for android.os.Build#IS_DEBUGGABLE

The following examples show how to use android.os.Build#IS_DEBUGGABLE . These examples are extracted from open source projects. 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
@Override
public void onBootPhase(int phase) {
    if (phase == SystemService.PHASE_THIRD_PARTY_APPS_CAN_START) {
        if (Build.IS_DEBUGGABLE) {
            SystemProperties.addChangeCallback(mSystemPropertiesChanged);
        }
        mContext.registerReceiver(new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                writePulseGestureEnabled();
                synchronized (mLock) {
                    stopDreamLocked(false /*immediate*/);
                }
            }
        }, new IntentFilter(Intent.ACTION_USER_SWITCHED), null, mHandler);
        mContext.getContentResolver().registerContentObserver(
                Settings.Secure.getUriFor(Settings.Secure.DOZE_PULSE_ON_DOUBLE_TAP), false,
                mDozeEnabledObserver, UserHandle.USER_ALL);
        writePulseGestureEnabled();
    }
}
 
Example 2
private void setProperty(String key, String value) {
    // Check if need to clear the property
    if (value == null) {
        // It's impossible to remove system property, therefore we check previous value to
        // avoid setting an empty string if the property wasn't set.
        if (TextUtils.isEmpty(systemPropertiesGet(key))) {
            return;
        }
        value = "";
    }
    try {
        systemPropertiesSet(key, value);
    } catch (Exception e) {
        // Failure to set a property can be caused by SELinux denial. This usually indicates
        // that the property wasn't whitelisted in sepolicy.
        // No need to report it on all user devices, only on debug builds.
        if (Build.IS_DEBUGGABLE) {
            Slog.wtf(TAG, "Unable to set property " + key + " value '" + value + "'", e);
        } else {
            Slog.e(TAG, "Unable to set property " + key + " value '" + value + "'", e);
        }
    }
}
 
Example 3
/**
 * Gets the the result of an async request that returns {@link AccessibilityNodeInfo}s.
 *
 * @param interactionId The interaction id to match the result with the request.
 * @return The result {@link AccessibilityNodeInfo}s.
 */
private List<AccessibilityNodeInfo> getFindAccessibilityNodeInfosResultAndClear(
            int interactionId) {
    synchronized (mInstanceLock) {
        final boolean success = waitForResultTimedLocked(interactionId);
        final List<AccessibilityNodeInfo> result;
        if (success) {
            result = mFindAccessibilityNodeInfosResult;
        } else {
            result = Collections.emptyList();
        }
        clearResultLocked();
        if (Build.IS_DEBUGGABLE && CHECK_INTEGRITY) {
            checkFindAccessibilityNodeInfoResultIntegrity(result);
        }
        return result;
    }
}
 
Example 4
public SettingsState(Context context, Object lock, File file, int key,
        int maxBytesPerAppPackage, Looper looper) {
    // It is important that we use the same lock as the settings provider
    // to ensure multiple mutations on this state are atomicaly persisted
    // as the async persistence should be blocked while we make changes.
    mContext = context;
    mLock = lock;
    mStatePersistFile = file;
    mKey = key;
    mHandler = new MyHandler(looper);
    if (maxBytesPerAppPackage == MAX_BYTES_PER_APP_PACKAGE_LIMITED) {
        mMaxBytesPerAppPackage = maxBytesPerAppPackage;
        mPackageToMemoryUsage = new ArrayMap<>();
    } else {
        mMaxBytesPerAppPackage = maxBytesPerAppPackage;
        mPackageToMemoryUsage = null;
    }

    mHistoricalOperations = Build.IS_DEBUGGABLE
            ? new ArrayList<>(HISTORICAL_OPERATION_COUNT) : null;

    synchronized (mLock) {
        readStateSyncLocked();
    }
}
 
Example 5
Source Project: android_9.0.0_r45   File: SyncLogger.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @return the singleton instance.
 */
public static synchronized SyncLogger getInstance() {
    if (sInstance == null) {
        final boolean enable =
                Build.IS_DEBUGGABLE
                || "1".equals(SystemProperties.get("debug.synclog"))
                || Log.isLoggable(TAG, Log.VERBOSE);
        if (enable) {
            sInstance = new RotatingFileLogger();
        } else {
            sInstance = new SyncLogger();
        }
    }
    return sInstance;
}
 
Example 6
Source Project: android_9.0.0_r45   File: DexManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Generates package related log if the package has code stored in unexpected way.
 */
public static void maybeLogUnexpectedPackageDetails(PackageParser.Package pkg) {
    if (!Build.IS_DEBUGGABLE) {
        return;
    }

    if (pkg.isPrivileged() && isPackageSelectedToRunOob(pkg.packageName)) {
        logIfPackageHasUncompressedCode(pkg);
    }
}
 
Example 7
@VisibleForTesting
static int getMaxManagedProfiles() {
    // Allow overriding max managed profiles on debuggable builds for testing
    // of multiple profiles.
    if (!Build.IS_DEBUGGABLE) {
        return MAX_MANAGED_PROFILES;
    } else {
        return SystemProperties.getInt("persist.sys.max_profiles",
                MAX_MANAGED_PROFILES);
    }
}
 
Example 8
private LocalSocketAddress determineSocketAddress() {
    // If we're testing, set up a socket in a namespace that's accessible to test code.
    // In order to ensure that unprivileged apps aren't able to impersonate native daemons on
    // production devices, even if said native daemons ill-advisedly pick a socket name that
    // starts with __test__, only allow this on debug builds.
    if (mSocket.startsWith("__test__") && Build.IS_DEBUGGABLE) {
        return new LocalSocketAddress(mSocket);
    } else {
        return new LocalSocketAddress(mSocket, LocalSocketAddress.Namespace.RESERVED);
    }
}
 
Example 9
Source Project: android_9.0.0_r45   File: Watchdog.java    License: Apache License 2.0 5 votes vote down vote up
public static OpenFdMonitor create() {
    // Only run the FD monitor on debuggable builds (such as userdebug and eng builds).
    if (!Build.IS_DEBUGGABLE) {
        return null;
    }

    // Don't run the FD monitor on builds that have a global ANR trace file. We're using
    // the ANR trace directory as a quick hack in order to get these traces in bugreports
    // and we wouldn't want to overwrite something important.
    final String dumpDirStr = SystemProperties.get("dalvik.vm.stack-trace-dir", "");
    if (dumpDirStr.isEmpty()) {
        return null;
    }

    final StructRlimit rlimit;
    try {
        rlimit = android.system.Os.getrlimit(OsConstants.RLIMIT_NOFILE);
    } catch (ErrnoException errno) {
        Slog.w(TAG, "Error thrown from getrlimit(RLIMIT_NOFILE)", errno);
        return null;
    }

    // The assumption we're making here is that FD numbers are allocated (more or less)
    // sequentially, which is currently (and historically) true since open is currently
    // specified to always return the lowest-numbered non-open file descriptor for the
    // current process.
    //
    // We do this to avoid having to enumerate the contents of /proc/self/fd in order to
    // count the number of descriptors open in the process.
    final File fdThreshold = new File("/proc/self/fd/" + (rlimit.rlim_cur - FD_HIGH_WATER_MARK));
    return new OpenFdMonitor(new File(dumpDirStr), fdThreshold);
}
 
Example 10
/** @hide */
public static boolean isLowRamDeviceStatic() {
    return RoSystemProperties.CONFIG_LOW_RAM ||
            (Build.IS_DEBUGGABLE && DEVELOPMENT_FORCE_LOW_RAM);
}
 
Example 11
Source Project: android_9.0.0_r45   File: SystemImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public boolean systemIsDebuggable() {
    return Build.IS_DEBUGGABLE;
}
 
Example 12
/**
 * Perform a query by combining all current settings and the
 * information passed into this method.
 *
 * @param db the database to query on
 * @param projectionIn A list of which columns to return. Passing
 *   null will return all columns, which is discouraged to prevent
 *   reading data from storage that isn't going to be used.
 * @param selection A filter declaring which rows to return,
 *   formatted as an SQL WHERE clause (excluding the WHERE
 *   itself). Passing null will return all rows for the given URL.
 * @param selectionArgs You may include ?s in selection, which
 *   will be replaced by the values from selectionArgs, in order
 *   that they appear in the selection. The values will be bound
 *   as Strings.
 * @param groupBy A filter declaring how to group rows, formatted
 *   as an SQL GROUP BY clause (excluding the GROUP BY
 *   itself). Passing null will cause the rows to not be grouped.
 * @param having A filter declare which row groups to include in
 *   the cursor, if row grouping is being used, formatted as an
 *   SQL HAVING clause (excluding the HAVING itself).  Passing
 *   null will cause all row groups to be included, and is
 *   required when row grouping is not being used.
 * @param sortOrder How to order the rows, formatted as an SQL
 *   ORDER BY clause (excluding the ORDER BY itself). Passing null
 *   will use the default sort order, which may be unordered.
 * @param limit Limits the number of rows returned by the query,
 *   formatted as LIMIT clause. Passing null denotes no LIMIT clause.
 * @param cancellationSignal A signal to cancel the operation in progress, or null if none.
 * If the operation is canceled, then {@link OperationCanceledException} will be thrown
 * when the query is executed.
 * @return a cursor over the result set
 * @see android.content.ContentResolver#query(android.net.Uri, String[],
 *      String, String[], String)
 */
public Cursor query(SQLiteDatabase db, String[] projectionIn,
        String selection, String[] selectionArgs, String groupBy,
        String having, String sortOrder, String limit, CancellationSignal cancellationSignal) {
    if (mTables == null) {
        return null;
    }

    final String sql;
    final String unwrappedSql = buildQuery(
            projectionIn, selection, groupBy, having,
            sortOrder, limit);

    if (mStrict && selection != null && selection.length() > 0) {
        // Validate the user-supplied selection to detect syntactic anomalies
        // in the selection string that could indicate a SQL injection attempt.
        // The idea is to ensure that the selection clause is a valid SQL expression
        // by compiling it twice: once wrapped in parentheses and once as
        // originally specified. An attacker cannot create an expression that
        // would escape the SQL expression while maintaining balanced parentheses
        // in both the wrapped and original forms.

        // NOTE: The ordering of the below operations is important; we must
        // execute the wrapped query to ensure the untrusted clause has been
        // fully isolated.

        // Validate the unwrapped query
        db.validateSql(unwrappedSql, cancellationSignal); // will throw if query is invalid

        // Execute wrapped query for extra protection
        final String wrappedSql = buildQuery(projectionIn, wrap(selection), groupBy,
                having, sortOrder, limit);
        sql = wrappedSql;
    } else {
        // Execute unwrapped query
        sql = unwrappedSql;
    }

    final String[] sqlArgs = selectionArgs;
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        if (Build.IS_DEBUGGABLE) {
            Log.d(TAG, sql + " with args " + Arrays.toString(sqlArgs));
        } else {
            Log.d(TAG, sql);
        }
    }
    return db.rawQueryWithFactory(
            mFactory, sql, sqlArgs,
            SQLiteDatabase.findEditTable(mTables),
            cancellationSignal); // will throw if query is invalid
}
 
Example 13
/**
 * Perform an update by combining all current settings and the
 * information passed into this method.
 *
 * @param db the database to update on
 * @param selection A filter declaring which rows to return,
 *   formatted as an SQL WHERE clause (excluding the WHERE
 *   itself). Passing null will return all rows for the given URL.
 * @param selectionArgs You may include ?s in selection, which
 *   will be replaced by the values from selectionArgs, in order
 *   that they appear in the selection. The values will be bound
 *   as Strings.
 * @return the number of rows updated
 * @hide
 */
public int update(@NonNull SQLiteDatabase db, @NonNull ContentValues values,
        @Nullable String selection, @Nullable String[] selectionArgs) {
    Objects.requireNonNull(mTables, "No tables defined");
    Objects.requireNonNull(db, "No database defined");
    Objects.requireNonNull(values, "No values defined");

    final String sql;
    final String unwrappedSql = buildUpdate(values, selection);

    if (mStrict) {
        // Validate the user-supplied selection to detect syntactic anomalies
        // in the selection string that could indicate a SQL injection attempt.
        // The idea is to ensure that the selection clause is a valid SQL expression
        // by compiling it twice: once wrapped in parentheses and once as
        // originally specified. An attacker cannot create an expression that
        // would escape the SQL expression while maintaining balanced parentheses
        // in both the wrapped and original forms.

        // NOTE: The ordering of the below operations is important; we must
        // execute the wrapped query to ensure the untrusted clause has been
        // fully isolated.

        // Validate the unwrapped query
        db.validateSql(unwrappedSql, null); // will throw if query is invalid

        // Execute wrapped query for extra protection
        final String wrappedSql = buildUpdate(values, wrap(selection));
        sql = wrappedSql;
    } else {
        // Execute unwrapped query
        sql = unwrappedSql;
    }

    if (selectionArgs == null) {
        selectionArgs = EmptyArray.STRING;
    }
    final String[] rawKeys = values.keySet().toArray(EmptyArray.STRING);
    final int valuesLength = rawKeys.length;
    final Object[] sqlArgs = new Object[valuesLength + selectionArgs.length];
    for (int i = 0; i < sqlArgs.length; i++) {
        if (i < valuesLength) {
            sqlArgs[i] = values.get(rawKeys[i]);
        } else {
            sqlArgs[i] = selectionArgs[i - valuesLength];
        }
    }
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        if (Build.IS_DEBUGGABLE) {
            Log.d(TAG, sql + " with args " + Arrays.toString(sqlArgs));
        } else {
            Log.d(TAG, sql);
        }
    }
    return db.executeSql(sql, sqlArgs);
}
 
Example 14
/**
 * Perform a delete by combining all current settings and the
 * information passed into this method.
 *
 * @param db the database to delete on
 * @param selection A filter declaring which rows to return,
 *   formatted as an SQL WHERE clause (excluding the WHERE
 *   itself). Passing null will return all rows for the given URL.
 * @param selectionArgs You may include ?s in selection, which
 *   will be replaced by the values from selectionArgs, in order
 *   that they appear in the selection. The values will be bound
 *   as Strings.
 * @return the number of rows deleted
 * @hide
 */
public int delete(@NonNull SQLiteDatabase db, @Nullable String selection,
        @Nullable String[] selectionArgs) {
    Objects.requireNonNull(mTables, "No tables defined");
    Objects.requireNonNull(db, "No database defined");

    final String sql;
    final String unwrappedSql = buildDelete(selection);

    if (mStrict) {
        // Validate the user-supplied selection to detect syntactic anomalies
        // in the selection string that could indicate a SQL injection attempt.
        // The idea is to ensure that the selection clause is a valid SQL expression
        // by compiling it twice: once wrapped in parentheses and once as
        // originally specified. An attacker cannot create an expression that
        // would escape the SQL expression while maintaining balanced parentheses
        // in both the wrapped and original forms.

        // NOTE: The ordering of the below operations is important; we must
        // execute the wrapped query to ensure the untrusted clause has been
        // fully isolated.

        // Validate the unwrapped query
        db.validateSql(unwrappedSql, null); // will throw if query is invalid

        // Execute wrapped query for extra protection
        final String wrappedSql = buildDelete(wrap(selection));
        sql = wrappedSql;
    } else {
        // Execute unwrapped query
        sql = unwrappedSql;
    }

    final String[] sqlArgs = selectionArgs;
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        if (Build.IS_DEBUGGABLE) {
            Log.d(TAG, sql + " with args " + Arrays.toString(sqlArgs));
        } else {
            Log.d(TAG, sql);
        }
    }
    return db.executeSql(sql, sqlArgs);
}
 
Example 15
/** @hide */
public static boolean isLowRamDeviceStatic() {
    return RoSystemProperties.CONFIG_LOW_RAM ||
            (Build.IS_DEBUGGABLE && DEVELOPMENT_FORCE_LOW_RAM);
}
 
Example 16
private static boolean isUnsafeBuild() {
    return Build.IS_DEBUGGABLE && Build.IS_ENG;
}
 
Example 17
private static boolean isCallerSystemOrShellOrRootOnDebuggableBuild() {
    final int appId = UserHandle.getAppId(Binder.getCallingUid());
    return appId == SYSTEM_UID || (Build.IS_DEBUGGABLE
            && (appId == SHELL_UID || appId == ROOT_UID));
}