public class

SystemProperty

extends java.lang.Object

 java.lang.Object

↳androidx.input.motionprediction.common.SystemProperty

Gradle dependencies

compile group: 'androidx.input', name: 'input-motionprediction', version: '1.0.0-beta04'

  • groupId: androidx.input
  • artifactId: input-motionprediction
  • version: 1.0.0-beta04

Artifact androidx.input:input-motionprediction:1.0.0-beta04 it located at Google repository (https://maven.google.com/)

Summary

Methods
public static booleangetBoolean(java.lang.String name)

Reads a system property and returns its boolean value.

public static intgetInt(java.lang.String name)

Reads a system property and returns its integer value.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Methods

public static boolean getBoolean(java.lang.String name)

Reads a system property and returns its boolean value.

Parameters:

name: the name of the system property

Returns:

true if the property is set and true, false otherwise

public static int getInt(java.lang.String name)

Reads a system property and returns its integer value.

Parameters:

name: the name of the system property

Returns:

the integer value of the property if defined, zero otherwise

Source

/*
 * Copyright 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.input.motionprediction.common;

import static androidx.annotation.RestrictTo.Scope.LIBRARY;

import android.annotation.SuppressLint;

import androidx.annotation.NonNull;
import androidx.annotation.RestrictTo;

import java.lang.reflect.Method;

/**
 */
@RestrictTo(LIBRARY)
public class SystemProperty {
    private static final boolean BOOLEAN_PROPERTY_DEFAULT = false;
    private static final int INT_PROPERTY_DEFAULT = 0;

    private SystemProperty() {
        // This class is non-instantiable.
    }

    /**
     * Reads a system property and returns its boolean value.
     *
     * @param name the name of the system property
     * @return true if the property is set and true, false otherwise
     */
    public static boolean getBoolean(@NonNull String name) {
        try {
            @SuppressLint("PrivateApi")
            Class<?> systemProperties = Class.forName("android.os.SystemProperties");
            Method getMethod = systemProperties.getMethod(
                    "getBoolean",
                    String.class,
                    boolean.class);
            @SuppressLint("BanUncheckedReflection")
            Boolean result = (Boolean) getMethod.invoke(
                    systemProperties,
                    name,
                    BOOLEAN_PROPERTY_DEFAULT);
            if (result != null) {
                return result.booleanValue();
            }
        } catch (Exception e) {
        }
        return BOOLEAN_PROPERTY_DEFAULT;
    }

    /**
     * Reads a system property and returns its integer value.
     *
     * @param name the name of the system property
     * @return the integer value of the property if defined, zero otherwise
     */
    public static int getInt(@NonNull String name) {
        try {
            @SuppressLint("PrivateApi")
            Class<?> systemProperties = Class.forName("android.os.SystemProperties");
            Method getMethod = systemProperties.getMethod(
                    "getInt",
                    String.class,
                    int.class);
            @SuppressLint("BanUncheckedReflection")
            Integer result = (Integer) getMethod.invoke(
                    systemProperties,
                    name,
                    INT_PROPERTY_DEFAULT);
            if (result != null) {
                return result.intValue();
            }
        } catch (Exception e) {
        }
        return INT_PROPERTY_DEFAULT;
    }
}