103e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataoka/*
203e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataoka * Copyright (C) 2013 The Android Open Source Project
303e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataoka *
403e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataoka * Licensed under the Apache License, Version 2.0 (the "License");
503e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataoka * you may not use this file except in compliance with the License.
603e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataoka * You may obtain a copy of the License at
703e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataoka *
803e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataoka *      http://www.apache.org/licenses/LICENSE-2.0
903e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataoka *
1003e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataoka * Unless required by applicable law or agreed to in writing, software
1103e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataoka * distributed under the License is distributed on an "AS IS" BASIS,
1203e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataoka * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1303e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataoka * See the License for the specific language governing permissions and
1403e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataoka * limitations under the License.
1503e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataoka */
1603e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataoka
1703e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataokapackage com.android.inputmethod.compat;
1803e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataoka
1903e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataokaimport android.app.ActivityManager;
2003e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataokaimport android.content.Context;
2103e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataoka
2203e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataokaimport java.lang.reflect.Method;
2303e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataoka
2403e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataokapublic class ActivityManagerCompatUtils {
2503e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataoka    private static final Object LOCK = new Object();
2603e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataoka    private static volatile Boolean sBoolean = null;
2703e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataoka    private static final Method METHOD_isLowRamDevice = CompatUtils.getMethod(
2803e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataoka            ActivityManager.class, "isLowRamDevice");
2903e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataoka
3003e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataoka    private ActivityManagerCompatUtils() {
3103e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataoka        // Do not instantiate this class.
3203e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataoka    }
3303e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataoka
3403e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataoka    public static boolean isLowRamDevice(Context context) {
3503e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataoka        if (sBoolean == null) {
3603e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataoka            synchronized(LOCK) {
3703e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataoka                if (sBoolean == null) {
3803e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataoka                    final ActivityManager am =
3903e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataoka                            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
4003e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataoka                    sBoolean = (Boolean)CompatUtils.invoke(am, false, METHOD_isLowRamDevice);
4103e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataoka                }
4203e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataoka            }
4303e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataoka        }
4403e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataoka        return sBoolean;
4503e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataoka    }
4603e55efe0360351b9ca9621a6528e78a6b165a0cSatoshi Kataoka}
47