Actions: Robustify
* Use not deprecated APIs where possible * Added some NPE safety checks * General cleaning of unsed code
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
<original-package android:name="com.cyanogenmod.settings.device" />
|
<original-package android:name="com.cyanogenmod.settings.device" />
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
|
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
|
||||||
|
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
|
||||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
|
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
|
||||||
<uses-permission android:name="android.permission.VIBRATE"/>
|
<uses-permission android:name="android.permission.VIBRATE"/>
|
||||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
package com.moto.actions;
|
package com.moto.actions;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import android.preference.PreferenceActivity;
|
import android.preference.PreferenceActivity;
|
||||||
|
|
||||||
public class ActionsPreferenceActivity extends PreferenceActivity {
|
public class ActionsPreferenceActivity extends PreferenceActivity {
|
||||||
@@ -25,9 +24,12 @@ public class ActionsPreferenceActivity extends PreferenceActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
if (savedInstanceState == null){
|
|
||||||
|
if (getActionBar() != null) {
|
||||||
|
getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
getFragmentManager().beginTransaction()
|
getFragmentManager().beginTransaction()
|
||||||
.replace(android.R.id.content, new ActionsPreferenceFragment()).commit();
|
.replace(android.R.id.content, new ActionsPreferenceFragment()).commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -21,11 +21,6 @@ import android.os.Bundle;
|
|||||||
import android.support.v14.preference.PreferenceFragment;
|
import android.support.v14.preference.PreferenceFragment;
|
||||||
|
|
||||||
public class ActionsPreferenceFragment extends PreferenceFragment {
|
public class ActionsPreferenceFragment extends PreferenceFragment {
|
||||||
@Override
|
|
||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
|
||||||
super.onActivityCreated(savedInstanceState);
|
|
||||||
getActivity().getActionBar().setDisplayHomeAsUpEnabled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ import android.content.ServiceConnection;
|
|||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.moto.actions.util.FileUtils;
|
|
||||||
import com.moto.actions.actions.Constants;
|
import com.moto.actions.actions.Constants;
|
||||||
import com.moto.actions.ServiceWrapper.LocalBinder;
|
import com.moto.actions.ServiceWrapper.LocalBinder;
|
||||||
|
|
||||||
@@ -41,6 +40,10 @@ public class BootCompletedReceiver extends BroadcastReceiver {
|
|||||||
public void onReceive(final Context context, Intent intent) {
|
public void onReceive(final Context context, Intent intent) {
|
||||||
Log.i(TAG, "Booting");
|
Log.i(TAG, "Booting");
|
||||||
|
|
||||||
|
if (intent.getAction() != null && !intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Restore nodes to saved preference values
|
// Restore nodes to saved preference values
|
||||||
for (String pref : Constants.sPrefKeys) {
|
for (String pref : Constants.sPrefKeys) {
|
||||||
Constants.writePreference(context, pref);
|
Constants.writePreference(context, pref);
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
package com.moto.actions;
|
package com.moto.actions;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import android.preference.PreferenceActivity;
|
import android.preference.PreferenceActivity;
|
||||||
|
|
||||||
public class DozeSettingsActivity extends PreferenceActivity {
|
public class DozeSettingsActivity extends PreferenceActivity {
|
||||||
@@ -25,9 +24,12 @@ public class DozeSettingsActivity extends PreferenceActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
if (savedInstanceState == null){
|
if (getActionBar() != null) {
|
||||||
getFragmentManager().beginTransaction()
|
getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
.replace(android.R.id.content, new DozeSettingsFragment()).commit();
|
getActionBar().setTitle(R.string.ambient_display_title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getFragmentManager().beginTransaction()
|
||||||
|
.replace(android.R.id.content, new DozeSettingsFragment()).commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.moto.actions;
|
package com.moto.actions;
|
||||||
|
|
||||||
import android.app.ActionBar;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v14.preference.PreferenceFragment;
|
import android.support.v14.preference.PreferenceFragment;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
@@ -41,14 +40,6 @@ public class DozeSettingsFragment extends PreferenceFragment {
|
|||||||
private String KEY_GESTURE_HAND_WAVE = "gesture_hand_wave";
|
private String KEY_GESTURE_HAND_WAVE = "gesture_hand_wave";
|
||||||
private String KEY_GESTURE_PICK_UP = "gesture_pick_up";
|
private String KEY_GESTURE_PICK_UP = "gesture_pick_up";
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
|
||||||
super.onActivityCreated(savedInstanceState);
|
|
||||||
ActionBar actionbar = getActivity().getActionBar();
|
|
||||||
actionbar.setDisplayHomeAsUpEnabled(true);
|
|
||||||
actionbar.setTitle(R.string.ambient_display_title);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
|
|||||||
@@ -25,9 +25,13 @@ public class FPGestureSettingsActivity extends PreferenceActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
if (savedInstanceState == null){
|
|
||||||
|
if (getActionBar() != null) {
|
||||||
|
getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
getActionBar().setTitle(R.string.fingerprint_gestures_title);
|
||||||
|
}
|
||||||
|
|
||||||
getFragmentManager().beginTransaction()
|
getFragmentManager().beginTransaction()
|
||||||
.replace(android.R.id.content, new FPGestureSettingsFragment()).commit();
|
.replace(android.R.id.content, new FPGestureSettingsFragment()).commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -47,14 +47,6 @@ public class FPGestureSettingsFragment extends PreferenceFragment {
|
|||||||
private TextView mSwitchBarText;
|
private TextView mSwitchBarText;
|
||||||
private Switch mFPGestureSwitch;
|
private Switch mFPGestureSwitch;
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
|
||||||
super.onActivityCreated(savedInstanceState);
|
|
||||||
ActionBar actionbar = getActivity().getActionBar();
|
|
||||||
actionbar.setDisplayHomeAsUpEnabled(true);
|
|
||||||
actionbar.setTitle(R.string.fingerprint_gestures_title);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
|
|||||||
@@ -25,9 +25,12 @@ public class GestureSettingsActivity extends PreferenceActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
if (savedInstanceState == null){
|
|
||||||
|
if (getActionBar() != null) {
|
||||||
|
getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
getFragmentManager().beginTransaction()
|
getFragmentManager().beginTransaction()
|
||||||
.replace(android.R.id.content, new GestureSettingsFragment()).commit();
|
.replace(android.R.id.content, new GestureSettingsFragment()).commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -21,12 +21,6 @@ import android.support.v14.preference.PreferenceFragment;
|
|||||||
|
|
||||||
public class GestureSettingsFragment extends PreferenceFragment {
|
public class GestureSettingsFragment extends PreferenceFragment {
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
|
||||||
super.onActivityCreated(savedInstanceState);
|
|
||||||
getActivity().getActionBar().setDisplayHomeAsUpEnabled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||||
addPreferencesFromResource(R.xml.actions_panel);
|
addPreferencesFromResource(R.xml.actions_panel);
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import android.app.IntentService;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.provider.Settings;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -44,44 +43,38 @@ public class MotoActionsService extends IntentService implements ScreenStateNoti
|
|||||||
UpdatedStateNotifier {
|
UpdatedStateNotifier {
|
||||||
private static final String TAG = "MotoActions";
|
private static final String TAG = "MotoActions";
|
||||||
|
|
||||||
private final Context mContext;
|
|
||||||
|
|
||||||
private final DozePulseAction mDozePulseAction;
|
|
||||||
private final PowerManager mPowerManager;
|
private final PowerManager mPowerManager;
|
||||||
private final PowerManager.WakeLock mWakeLock;
|
private final PowerManager.WakeLock mWakeLock;
|
||||||
private final ScreenReceiver mScreenReceiver;
|
|
||||||
private final SensorHelper mSensorHelper;
|
|
||||||
|
|
||||||
private final List<ScreenStateNotifier> mScreenStateNotifiers = new LinkedList<ScreenStateNotifier>();
|
private final List<ScreenStateNotifier> mScreenStateNotifiers = new LinkedList<>();
|
||||||
private final List<UpdatedStateNotifier> mUpdatedStateNotifiers =
|
private final List<UpdatedStateNotifier> mUpdatedStateNotifiers = new LinkedList<>();
|
||||||
new LinkedList<UpdatedStateNotifier>();
|
|
||||||
|
|
||||||
public MotoActionsService(Context context) {
|
public MotoActionsService(Context context) {
|
||||||
super("MotoActionService");
|
super("MotoActionService");
|
||||||
mContext = context;
|
|
||||||
|
|
||||||
Log.d(TAG, "Starting");
|
Log.d(TAG, "Starting");
|
||||||
|
|
||||||
MotoActionsSettings motoActionsSettings = new MotoActionsSettings(context, this);
|
MotoActionsSettings motoActionsSettings = new MotoActionsSettings(context, this);
|
||||||
mSensorHelper = new SensorHelper(context);
|
SensorHelper sensorHelper = new SensorHelper(context);
|
||||||
mScreenReceiver = new ScreenReceiver(context, this);
|
new ScreenReceiver(context, this);
|
||||||
|
|
||||||
mDozePulseAction = new DozePulseAction(context);
|
DozePulseAction mDozePulseAction = new DozePulseAction(context);
|
||||||
mScreenStateNotifiers.add(mDozePulseAction);
|
mScreenStateNotifiers.add(mDozePulseAction);
|
||||||
|
|
||||||
// Actionable sensors get screen on/off notifications
|
// Actionable sensors get screen on/off notifications
|
||||||
mScreenStateNotifiers.add(new GlanceSensor(motoActionsSettings, mSensorHelper, mDozePulseAction));
|
mScreenStateNotifiers.add(new GlanceSensor(motoActionsSettings, sensorHelper, mDozePulseAction));
|
||||||
mScreenStateNotifiers.add(new ProximitySensor(motoActionsSettings, mSensorHelper, mDozePulseAction));
|
mScreenStateNotifiers.add(new ProximitySensor(motoActionsSettings, sensorHelper, mDozePulseAction));
|
||||||
|
|
||||||
// Other actions that are always enabled
|
// Other actions that are always enabled
|
||||||
mUpdatedStateNotifiers.add(new CameraActivationSensor(motoActionsSettings, mSensorHelper));
|
mUpdatedStateNotifiers.add(new CameraActivationSensor(motoActionsSettings, sensorHelper));
|
||||||
mUpdatedStateNotifiers.add(new ChopChopSensor(motoActionsSettings, mSensorHelper));
|
mUpdatedStateNotifiers.add(new ChopChopSensor(motoActionsSettings, sensorHelper));
|
||||||
mUpdatedStateNotifiers.add(new ProximitySilencer(motoActionsSettings, context, mSensorHelper));
|
mUpdatedStateNotifiers.add(new ProximitySilencer(motoActionsSettings, context, sensorHelper));
|
||||||
mUpdatedStateNotifiers.add(new FlipToMute(motoActionsSettings, context, mSensorHelper));
|
mUpdatedStateNotifiers.add(new FlipToMute(motoActionsSettings, context, sensorHelper));
|
||||||
mUpdatedStateNotifiers.add(new LiftToSilence(motoActionsSettings, context, mSensorHelper));
|
mUpdatedStateNotifiers.add(new LiftToSilence(motoActionsSettings, context, sensorHelper));
|
||||||
|
|
||||||
mPowerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
mPowerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||||
mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MotoActionsWakeLock");
|
String tag = context.getPackageName() + ":ServiceWakeLock";
|
||||||
|
mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, tag);
|
||||||
updateState();
|
updateState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import com.moto.actions.actions.UpdatedStateNotifier;
|
|||||||
import com.moto.actions.actions.CameraActivationAction;
|
import com.moto.actions.actions.CameraActivationAction;
|
||||||
import com.moto.actions.actions.TorchAction;
|
import com.moto.actions.actions.TorchAction;
|
||||||
|
|
||||||
public class MotoActionsSettings {
|
public class MotoActionsSettings implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
private static final String TAG = "MotoActions";
|
private static final String TAG = "MotoActions";
|
||||||
|
|
||||||
private static final String GESTURE_CAMERA_ACTION_KEY = "gesture_camera_action";
|
private static final String GESTURE_CAMERA_ACTION_KEY = "gesture_camera_action";
|
||||||
@@ -55,7 +55,7 @@ public class MotoActionsSettings {
|
|||||||
public MotoActionsSettings(Context context, UpdatedStateNotifier updatedStateNotifier) {
|
public MotoActionsSettings(Context context, UpdatedStateNotifier updatedStateNotifier) {
|
||||||
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
|
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
loadPreferences(sharedPrefs);
|
loadPreferences(sharedPrefs);
|
||||||
sharedPrefs.registerOnSharedPreferenceChangeListener(mPrefListener);
|
sharedPrefs.registerOnSharedPreferenceChangeListener(this);
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mUpdatedStateNotifier = updatedStateNotifier;
|
mUpdatedStateNotifier = updatedStateNotifier;
|
||||||
}
|
}
|
||||||
@@ -114,8 +114,6 @@ public class MotoActionsSettings {
|
|||||||
mLiftToSilenceEnabled = sharedPreferences.getBoolean(GESTURE_LIFT_TO_SILENCE_KEY, false);
|
mLiftToSilenceEnabled = sharedPreferences.getBoolean(GESTURE_LIFT_TO_SILENCE_KEY, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private SharedPreferences.OnSharedPreferenceChangeListener mPrefListener =
|
|
||||||
new SharedPreferences.OnSharedPreferenceChangeListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||||
boolean updated = true;
|
boolean updated = true;
|
||||||
@@ -146,5 +144,4 @@ public class MotoActionsSettings {
|
|||||||
mUpdatedStateNotifier.updateState();
|
mUpdatedStateNotifier.updateState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,5 +18,5 @@
|
|||||||
package com.moto.actions;
|
package com.moto.actions;
|
||||||
|
|
||||||
public interface SensorAction {
|
public interface SensorAction {
|
||||||
public void action();
|
void action();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import android.content.Context;
|
|||||||
import android.hardware.Sensor;
|
import android.hardware.Sensor;
|
||||||
import android.hardware.SensorEventListener;
|
import android.hardware.SensorEventListener;
|
||||||
import android.hardware.SensorManager;
|
import android.hardware.SensorManager;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
public class SensorHelper {
|
public class SensorHelper {
|
||||||
private static final String TAG = "MotoActions";
|
private static final String TAG = "MotoActions";
|
||||||
@@ -45,7 +44,7 @@ public class SensorHelper {
|
|||||||
|
|
||||||
public SensorHelper(Context context) {
|
public SensorHelper(Context context) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mSensorManager = (SensorManager) mContext .getSystemService(Context.SENSOR_SERVICE);
|
mSensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
|
||||||
dumpSensorsList();
|
dumpSensorsList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,8 +17,6 @@
|
|||||||
|
|
||||||
package com.moto.actions.actions;
|
package com.moto.actions.actions;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import android.app.KeyguardManager;
|
import android.app.KeyguardManager;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -28,12 +26,14 @@ import android.content.pm.PackageManager;
|
|||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.os.PowerManager.WakeLock;
|
import android.os.PowerManager.WakeLock;
|
||||||
|
import android.os.VibrationEffect;
|
||||||
import android.os.Vibrator;
|
import android.os.Vibrator;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import com.moto.actions.SensorAction;
|
import com.moto.actions.SensorAction;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class CameraActivationAction implements SensorAction {
|
public class CameraActivationAction implements SensorAction {
|
||||||
private static final String TAG = "MotoActions";
|
private static final String TAG = "MotoActions";
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ public class CameraActivationAction implements SensorAction {
|
|||||||
public void action() {
|
public void action() {
|
||||||
vibrate();
|
vibrate();
|
||||||
turnScreenOn();
|
turnScreenOn();
|
||||||
if (mKeyguardManager.inKeyguardRestrictedInputMode()) {
|
if (mKeyguardManager.isKeyguardLocked()) {
|
||||||
launchSecureCamera();
|
launchSecureCamera();
|
||||||
} else {
|
} else {
|
||||||
launchCamera();
|
launchCamera();
|
||||||
@@ -63,13 +63,16 @@ public class CameraActivationAction implements SensorAction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void vibrate() {
|
private void vibrate() {
|
||||||
Vibrator v = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
|
Vibrator vib = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
|
||||||
v.vibrate(500);
|
if (vib == null) return;
|
||||||
|
VibrationEffect effect = VibrationEffect.createOneShot(500, VibrationEffect.DEFAULT_AMPLITUDE);
|
||||||
|
vib.vibrate(effect);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void turnScreenOn() {
|
private void turnScreenOn() {
|
||||||
PowerManager.WakeLock wl = mPowerManager.newWakeLock(
|
String tag = mContext.getPackageName() + ":CameraWakeLock";
|
||||||
PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, TAG);
|
WakeLock wl = mPowerManager.newWakeLock(
|
||||||
|
PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, tag);
|
||||||
wl.acquire(TURN_SCREEN_ON_WAKE_LOCK_MS);
|
wl.acquire(TURN_SCREEN_ON_WAKE_LOCK_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,12 +17,9 @@
|
|||||||
|
|
||||||
package com.moto.actions.actions;
|
package com.moto.actions.actions;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import android.hardware.Sensor;
|
import android.hardware.Sensor;
|
||||||
import android.hardware.SensorEvent;
|
import android.hardware.SensorEvent;
|
||||||
import android.hardware.SensorEventListener;
|
import android.hardware.SensorEventListener;
|
||||||
import android.hardware.SensorManager;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.moto.actions.MotoActionsSettings;
|
import com.moto.actions.MotoActionsSettings;
|
||||||
@@ -31,20 +28,14 @@ import com.moto.actions.SensorHelper;
|
|||||||
public class CameraActivationSensor implements SensorEventListener, UpdatedStateNotifier {
|
public class CameraActivationSensor implements SensorEventListener, UpdatedStateNotifier {
|
||||||
private static final String TAG = "MotoActions-CameraSensor";
|
private static final String TAG = "MotoActions-CameraSensor";
|
||||||
|
|
||||||
private static final int TURN_SCREEN_ON_WAKE_LOCK_MS = 500;
|
|
||||||
|
|
||||||
private final MotoActionsSettings mMotoActionsSettings;
|
private final MotoActionsSettings mMotoActionsSettings;
|
||||||
private final SensorHelper mSensorHelper;
|
|
||||||
|
|
||||||
private final Sensor mSensor;
|
|
||||||
|
|
||||||
private boolean mIsEnabled;
|
private boolean mIsEnabled;
|
||||||
|
|
||||||
public CameraActivationSensor(MotoActionsSettings motoActionsSettings, SensorHelper sensorHelper) {
|
public CameraActivationSensor(MotoActionsSettings motoActionsSettings, SensorHelper sensorHelper) {
|
||||||
mMotoActionsSettings = motoActionsSettings;
|
mMotoActionsSettings = motoActionsSettings;
|
||||||
mSensorHelper = sensorHelper;
|
Sensor sensor = sensorHelper.getCameraActivationSensor();
|
||||||
mSensor = sensorHelper.getCameraActivationSensor();
|
sensorHelper.registerListener(sensor, this);
|
||||||
mSensorHelper.registerListener(mSensor, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -17,12 +17,9 @@
|
|||||||
|
|
||||||
package com.moto.actions.actions;
|
package com.moto.actions.actions;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import android.hardware.Sensor;
|
import android.hardware.Sensor;
|
||||||
import android.hardware.SensorEvent;
|
import android.hardware.SensorEvent;
|
||||||
import android.hardware.SensorEventListener;
|
import android.hardware.SensorEventListener;
|
||||||
import android.hardware.SensorManager;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.moto.actions.MotoActionsSettings;
|
import com.moto.actions.MotoActionsSettings;
|
||||||
@@ -31,8 +28,6 @@ import com.moto.actions.SensorHelper;
|
|||||||
public class ChopChopSensor implements SensorEventListener, UpdatedStateNotifier {
|
public class ChopChopSensor implements SensorEventListener, UpdatedStateNotifier {
|
||||||
private static final String TAG = "MotoActions-ChopChopSensor";
|
private static final String TAG = "MotoActions-ChopChopSensor";
|
||||||
|
|
||||||
private static final int TURN_SCREEN_ON_WAKE_LOCK_MS = 500;
|
|
||||||
|
|
||||||
private final MotoActionsSettings mMotoActionsSettings;
|
private final MotoActionsSettings mMotoActionsSettings;
|
||||||
private final SensorHelper mSensorHelper;
|
private final SensorHelper mSensorHelper;
|
||||||
private final Sensor mSensor;
|
private final Sensor mSensor;
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import android.content.IntentFilter;
|
|||||||
import android.hardware.Sensor;
|
import android.hardware.Sensor;
|
||||||
import android.hardware.SensorEvent;
|
import android.hardware.SensorEvent;
|
||||||
import android.hardware.SensorEventListener;
|
import android.hardware.SensorEventListener;
|
||||||
|
import android.os.VibrationEffect;
|
||||||
import android.os.Vibrator;
|
import android.os.Vibrator;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@@ -57,7 +58,9 @@ public class FlipToMute implements UpdatedStateNotifier {
|
|||||||
mStow = sensorHelper.getStowSensor();
|
mStow = sensorHelper.getStowSensor();
|
||||||
mNotificationManager =
|
mNotificationManager =
|
||||||
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
|
if (mNotificationManager != null) {
|
||||||
mFilter = mNotificationManager.getCurrentInterruptionFilter();
|
mFilter = mNotificationManager.getCurrentInterruptionFilter();
|
||||||
|
}
|
||||||
mReceiver = new Receiver();
|
mReceiver = new Receiver();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,8 +126,10 @@ public class FlipToMute implements UpdatedStateNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void vibrate() {
|
private void vibrate() {
|
||||||
Vibrator v = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
|
Vibrator vib = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
|
||||||
v.vibrate(250);
|
if (vib == null) return;
|
||||||
|
VibrationEffect effect = VibrationEffect.createOneShot(250, VibrationEffect.DEFAULT_AMPLITUDE);
|
||||||
|
vib.vibrate(effect);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Receiver extends BroadcastReceiver {
|
public class Receiver extends BroadcastReceiver {
|
||||||
@@ -132,6 +137,7 @@ public class FlipToMute implements UpdatedStateNotifier {
|
|||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
if (!mIsFlatDown && !mIsStowed) {
|
if (!mIsFlatDown && !mIsStowed) {
|
||||||
|
if (mNotificationManager == null) return;
|
||||||
mFilter = mNotificationManager.getCurrentInterruptionFilter();
|
mFilter = mNotificationManager.getCurrentInterruptionFilter();
|
||||||
Log.d(TAG, "Interrupt filter: Backup");
|
Log.d(TAG, "Interrupt filter: Backup");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,22 +72,18 @@ public class ProximitySilencer extends PhoneStateListener implements SensorEvent
|
|||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
|
|
||||||
if (isNear){
|
if (isNear){
|
||||||
if (mIsRinging && (now - mRingStartedMs >= SILENCE_DELAY_MS)){
|
mCoveredRinging = mIsRinging && (now - mRingStartedMs >= SILENCE_DELAY_MS);
|
||||||
mCoveredRinging = true;
|
|
||||||
} else {
|
|
||||||
mCoveredRinging = false;
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isNear && mIsRinging) {
|
if (mIsRinging) {
|
||||||
Log.d(TAG, "event: " + event.values[0] + ", " + " covered " + Boolean.toString(mCoveredRinging));
|
Log.d(TAG, "event: " + event.values[0] + ", " + " covered " + Boolean.toString(mCoveredRinging));
|
||||||
if (mCoveredRinging) {
|
if (mCoveredRinging) {
|
||||||
Log.d(TAG, "Silencing ringer");
|
Log.d(TAG, "Silencing ringer");
|
||||||
mTelecomManager.silenceRinger();
|
mTelecomManager.silenceRinger();
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "Ignoring silence gesture: " + now + " is too close to " +
|
Log.d(TAG, "Ignoring silence gesture: " + now + " is too close to " +
|
||||||
mRingStartedMs + ", delay=" + SILENCE_DELAY_MS + " or covered " + Boolean.toString(mCoveredRinging));
|
mRingStartedMs + ", delay=" + SILENCE_DELAY_MS);
|
||||||
}
|
}
|
||||||
mCoveredRinging = false;
|
mCoveredRinging = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,19 +18,18 @@
|
|||||||
package com.moto.actions.actions;
|
package com.moto.actions.actions;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.hardware.camera2.CameraManager;
|
|
||||||
import android.hardware.camera2.CameraCharacteristics;
|
|
||||||
import android.hardware.camera2.CameraAccessException;
|
import android.hardware.camera2.CameraAccessException;
|
||||||
|
import android.hardware.camera2.CameraCharacteristics;
|
||||||
|
import android.hardware.camera2.CameraManager;
|
||||||
|
import android.os.VibrationEffect;
|
||||||
import android.os.Vibrator;
|
import android.os.Vibrator;
|
||||||
import android.util.Log;
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import com.moto.actions.SensorAction;
|
import com.moto.actions.SensorAction;
|
||||||
|
|
||||||
public class TorchAction implements SensorAction {
|
public class TorchAction implements SensorAction {
|
||||||
private static final String TAG = "MotoActions";
|
private static final String TAG = "MotoActions";
|
||||||
|
|
||||||
private static final int TURN_SCREEN_ON_WAKE_LOCK_MS = 500;
|
|
||||||
|
|
||||||
private CameraManager mCameraManager;
|
private CameraManager mCameraManager;
|
||||||
private final Vibrator mVibrator;
|
private final Vibrator mVibrator;
|
||||||
private String mRearCameraId;
|
private String mRearCameraId;
|
||||||
@@ -51,17 +50,20 @@ public class TorchAction implements SensorAction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (CameraAccessException e) {
|
} catch (CameraAccessException e) {
|
||||||
|
// Noop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void action() {
|
public void action() {
|
||||||
mVibrator.vibrate(250);
|
VibrationEffect vibrationEffect = VibrationEffect.createOneShot(250, VibrationEffect.DEFAULT_AMPLITUDE);
|
||||||
|
mVibrator.vibrate(vibrationEffect);
|
||||||
if (mRearCameraId != null) {
|
if (mRearCameraId != null) {
|
||||||
try {
|
try {
|
||||||
mCameraManager.setTorchMode(mRearCameraId, !mTorchEnabled);
|
mCameraManager.setTorchMode(mRearCameraId, !mTorchEnabled);
|
||||||
mTorchEnabled = !mTorchEnabled;
|
mTorchEnabled = !mTorchEnabled;
|
||||||
} catch (CameraAccessException e) {
|
} catch (CameraAccessException e) {
|
||||||
|
// Noop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -69,14 +71,14 @@ public class TorchAction implements SensorAction {
|
|||||||
private class MyTorchCallback extends CameraManager.TorchCallback {
|
private class MyTorchCallback extends CameraManager.TorchCallback {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTorchModeChanged(String cameraId, boolean enabled) {
|
public void onTorchModeChanged(@NonNull String cameraId, boolean enabled) {
|
||||||
if (!cameraId.equals(mRearCameraId))
|
if (!cameraId.equals(mRearCameraId))
|
||||||
return;
|
return;
|
||||||
mTorchEnabled = enabled;
|
mTorchEnabled = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTorchModeUnavailable(String cameraId) {
|
public void onTorchModeUnavailable(@NonNull String cameraId) {
|
||||||
if (!cameraId.equals(mRearCameraId))
|
if (!cameraId.equals(mRearCameraId))
|
||||||
return;
|
return;
|
||||||
mTorchEnabled = false;
|
mTorchEnabled = false;
|
||||||
|
|||||||
@@ -18,5 +18,5 @@
|
|||||||
package com.moto.actions.actions;
|
package com.moto.actions.actions;
|
||||||
|
|
||||||
public interface UpdatedStateNotifier {
|
public interface UpdatedStateNotifier {
|
||||||
public void updateState();
|
void updateState();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public class DozePulseAction implements SensorAction, ScreenStateNotifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized boolean mayDoze() {
|
private synchronized boolean mayDoze() {
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
if (now - mLastDoze > DELAY_BETWEEN_DOZES_IN_MS) {
|
if (now - mLastDoze > DELAY_BETWEEN_DOZES_IN_MS) {
|
||||||
Log.d(TAG, "Allowing doze");
|
Log.d(TAG, "Allowing doze");
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ public class ScreenReceiver extends BroadcastReceiver {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
if (intent.getAction() == null) return;
|
||||||
|
|
||||||
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
|
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
|
||||||
mNotifier.screenTurnedOff();
|
mNotifier.screenTurnedOff();
|
||||||
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
|
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
|
||||||
|
|||||||
@@ -18,6 +18,6 @@
|
|||||||
package com.moto.actions.doze;
|
package com.moto.actions.doze;
|
||||||
|
|
||||||
public interface ScreenStateNotifier {
|
public interface ScreenStateNotifier {
|
||||||
public void screenTurnedOn();
|
void screenTurnedOn();
|
||||||
public void screenTurnedOff();
|
void screenTurnedOff();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user