sdm710-common: Add PocketMode app
This commit is contained in:
parent
78fe8f26f8
commit
470c614f62
7 changed files with 265 additions and 0 deletions
|
@ -281,6 +281,10 @@ PRODUCT_COPY_FILES += \
|
||||||
frameworks/native/data/etc/android.software.sip.voip.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.sip.voip.xml \
|
frameworks/native/data/etc/android.software.sip.voip.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.sip.voip.xml \
|
||||||
frameworks/native/data/etc/handheld_core_hardware.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/handheld_core_hardware.xml
|
frameworks/native/data/etc/handheld_core_hardware.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/handheld_core_hardware.xml
|
||||||
|
|
||||||
|
# PocketMode
|
||||||
|
PRODUCT_PACKAGES += \
|
||||||
|
LenovoPocketMode
|
||||||
|
|
||||||
# Power
|
# Power
|
||||||
PRODUCT_PACKAGES += \
|
PRODUCT_PACKAGES += \
|
||||||
android.hardware.power-service.lenovo
|
android.hardware.power-service.lenovo
|
||||||
|
|
16
pocketmode/Android.mk
Normal file
16
pocketmode/Android.mk
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
LOCAL_PATH:= $(call my-dir)
|
||||||
|
|
||||||
|
include $(CLEAR_VARS)
|
||||||
|
|
||||||
|
LOCAL_MODULE_TAGS := optional
|
||||||
|
|
||||||
|
LOCAL_SRC_FILES := $(call all-java-files-under, src)
|
||||||
|
|
||||||
|
LOCAL_PACKAGE_NAME := LenovoPocketMode
|
||||||
|
LOCAL_CERTIFICATE := platform
|
||||||
|
LOCAL_PRIVATE_PLATFORM_APIS := true
|
||||||
|
LOCAL_PRIVILEGED_MODULE := true
|
||||||
|
|
||||||
|
LOCAL_PROGUARD_FLAG_FILES := proguard.flags
|
||||||
|
|
||||||
|
include $(BUILD_PACKAGE)
|
45
pocketmode/AndroidManifest.xml
Normal file
45
pocketmode/AndroidManifest.xml
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright (C) 2016 The CyanogenMod Project
|
||||||
|
Copyright (C) 2017-2018 The LineageOS 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.
|
||||||
|
-->
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="org.lineageos.pocketmode"
|
||||||
|
android:versionCode="1"
|
||||||
|
android:versionName="1.0"
|
||||||
|
android:sharedUserId="android.uid.system">
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||||
|
|
||||||
|
<uses-sdk
|
||||||
|
android:minSdkVersion="27" />
|
||||||
|
|
||||||
|
<application
|
||||||
|
android:label="LenovoPocketMode"
|
||||||
|
android:persistent="true">
|
||||||
|
|
||||||
|
<receiver android:name=".BootCompletedReceiver">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
</intent-filter>
|
||||||
|
</receiver>
|
||||||
|
|
||||||
|
<service android:name=".PocketModeService"
|
||||||
|
android:permission="PocketModeService">
|
||||||
|
</service>
|
||||||
|
|
||||||
|
</application>
|
||||||
|
</manifest>
|
3
pocketmode/proguard.flags
Normal file
3
pocketmode/proguard.flags
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
-keep class org.lineageos.pocketmode.* {
|
||||||
|
*;
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2016 The CyanogenMod Project
|
||||||
|
* 2017 The LineageOS 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 org.lineageos.pocketmode;
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.UserHandle;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
public class BootCompletedReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
|
private static final String TAG = "LenovoPocketMode";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
Log.d(TAG, "Starting");
|
||||||
|
context.startServiceAsUser(new Intent(context, PocketModeService.class),
|
||||||
|
UserHandle.CURRENT);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,84 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2016 The CyanogenMod Project
|
||||||
|
* 2017 The LineageOS 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 org.lineageos.pocketmode;
|
||||||
|
|
||||||
|
import android.app.Service;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
|
import android.os.IBinder;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
public class PocketModeService extends Service {
|
||||||
|
private static final String TAG = "PocketModeService";
|
||||||
|
private static final boolean DEBUG = false;
|
||||||
|
|
||||||
|
private ProximitySensor mProximitySensor;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate() {
|
||||||
|
if (DEBUG) Log.d(TAG, "Creating service");
|
||||||
|
mProximitySensor = new ProximitySensor(this);
|
||||||
|
|
||||||
|
IntentFilter screenStateFilter = new IntentFilter();
|
||||||
|
screenStateFilter.addAction(Intent.ACTION_SCREEN_OFF);
|
||||||
|
screenStateFilter.addAction(Intent.ACTION_USER_PRESENT);
|
||||||
|
registerReceiver(mScreenStateReceiver, screenStateFilter);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
|
if (DEBUG) Log.d(TAG, "Starting service");
|
||||||
|
return START_STICKY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
if (DEBUG) Log.d(TAG, "Destroying service");
|
||||||
|
this.unregisterReceiver(mScreenStateReceiver);
|
||||||
|
mProximitySensor.disable();
|
||||||
|
super.onDestroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IBinder onBind(Intent intent) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onDeviceUnlocked() {
|
||||||
|
if (DEBUG) Log.d(TAG, "Device unlocked");
|
||||||
|
mProximitySensor.disable();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onDisplayOff() {
|
||||||
|
if (DEBUG) Log.d(TAG, "Display off");
|
||||||
|
mProximitySensor.enable();
|
||||||
|
}
|
||||||
|
|
||||||
|
private BroadcastReceiver mScreenStateReceiver = new BroadcastReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
if (intent.getAction().equals(Intent.ACTION_USER_PRESENT)) {
|
||||||
|
onDeviceUnlocked();
|
||||||
|
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
|
||||||
|
onDisplayOff();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
77
pocketmode/src/org/lineageos/pocketmode/ProximitySensor.java
Normal file
77
pocketmode/src/org/lineageos/pocketmode/ProximitySensor.java
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2016 The CyanogenMod Project
|
||||||
|
* 2017-2019 The LineageOS 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 org.lineageos.pocketmode;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.hardware.Sensor;
|
||||||
|
import android.hardware.SensorEvent;
|
||||||
|
import android.hardware.SensorEventListener;
|
||||||
|
import android.hardware.SensorManager;
|
||||||
|
import android.os.FileUtils;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
|
public class ProximitySensor implements SensorEventListener {
|
||||||
|
private static final String TAG = "PocketModeProximity";
|
||||||
|
private static final boolean DEBUG = false;
|
||||||
|
|
||||||
|
private ExecutorService mExecutorService;
|
||||||
|
private Context mContext;
|
||||||
|
private Sensor mSensor;
|
||||||
|
private SensorManager mSensorManager;
|
||||||
|
|
||||||
|
public ProximitySensor(Context context) {
|
||||||
|
mContext = context;
|
||||||
|
mSensorManager = mContext.getSystemService(SensorManager.class);
|
||||||
|
mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
|
||||||
|
mExecutorService = Executors.newSingleThreadExecutor();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Future<?> submit(Runnable runnable) {
|
||||||
|
return mExecutorService.submit(runnable);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSensorChanged(SensorEvent event) {
|
||||||
|
/* Empty */
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
||||||
|
/* Empty */
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void enable() {
|
||||||
|
if (DEBUG) Log.d(TAG, "Enabling");
|
||||||
|
submit(() -> {
|
||||||
|
mSensorManager.registerListener(this, mSensor,
|
||||||
|
SensorManager.SENSOR_DELAY_NORMAL);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void disable() {
|
||||||
|
if (DEBUG) Log.d(TAG, "Disabling");
|
||||||
|
submit(() -> {
|
||||||
|
mSensorManager.unregisterListener(this, mSensor);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue