#if JAVA
import android.os.Build;
import android.provider.Settings;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import java.util.List;
import java.lang.Boolean;
import android.util.Log;
private static Boolean helperPackageFound = null;
private static int result = -1;
private static Intent getIntent(int enabled, String mode) {
Intent intent = new Intent("PACKAGE_NAME_FOR_AODHELPERAPP.SET_AOD");
intent.setClassName("PACKAGE_NAME_FOR_AODHELPERAPP", "PACKAGE_NAME_FOR_AODHELPERAPP.AODReceiver");
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
intent.putExtra(mode + ".enable", enabled);
// Log.d("B4A", intent.toString());
return intent;
}
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
public static boolean haveHelperPackage(Context context, boolean refresh) {
if ((helperPackageFound != null) && !refresh) return helperPackageFound.booleanValue();
List<ResolveInfo> resolves = context.getPackageManager().queryBroadcastReceivers(getIntent(1, "SET_TAP_TO_SHOW"), 0);
for (ResolveInfo info : resolves) {
if (info.activityInfo != null) {
if (info.activityInfo.packageName.equals("com.NotifyMe.aodHelper")) {
helperPackageFound = true;
// Log.d("B4A", "helperPackageFound = " + helperPackageFound);
return true;
}
}
}
// Log.d("B4A", "helperPackageFound = " + helperPackageFound);
helperPackageFound = false;
return false;
}
@SuppressWarnings("deprecation")
public static int setAOD(Context context, int enabled, String mode) {
context.sendOrderedBroadcast(getIntent(enabled, mode), null, new BroadcastReceiver() {
@SuppressWarnings("all")
@Override
public void onReceive(Context context, Intent intent) {
// Log.d("B4A", "getResultCode = " + getResultCode());
result = getResultCode();
// if (getResultCode() != 1) {
//TODO raise the alarms, something went awry
// }
}
}, null, 0, null, null);
return result;
}
/* public static String getAODThemePackage(Context context) {
ContentResolver resolver = context.getContentResolver();
return android.provider.Settings.System.getString(resolver, "current_sec_aod_theme_package");
}
*/
public static int[] getAODSchedule(Context context) {
ContentResolver resolver = context.getContentResolver();
int start = android.provider.Settings.System.getInt(resolver, "aod_mode_start_time", 0);
int end = android.provider.Settings.System.getInt(resolver, "aod_mode_end_time", 0);
return new int[] { start, end };
}
public static int aodIsTapToShow(Context context){
ContentResolver resolver = context.getContentResolver();
return Settings.System.getInt(resolver, "aod_tap_to_show_mode", -1);
}
public static int aodIsEnabled(Context context){
ContentResolver resolver = context.getContentResolver();
return Settings.System.getInt(resolver, "aod_mode", -1);
}
public static int aodTapToShow(Context context, int state) {
if(Build.VERSION.SDK_INT >= 23 && !Settings.System.canWrite(context)) {
return -1;
}
try {
ContentResolver resolver = context.getContentResolver();
if(Settings.System.getInt(resolver, "aod_mode", -1) == 0){ //disabled so turn off
android.provider.Settings.System.putInt(resolver, "aod_mode", 1);
}
int mode = Settings.System.getInt(resolver, "aod_tap_to_show_mode", -1);
if(mode != state){
android.provider.Settings.System.putInt(resolver, "aod_tap_to_show_mode", state);
}
return 1; // Settings.System.getInt(resolver, "aod_tap_to_show_mode", -1);
}
catch (Exception e) {
// no permissions
e.printStackTrace();
return 2;
}
}
public static int aodEnable(Context context, int state) {
if(Build.VERSION.SDK_INT >= 23 && !Settings.System.canWrite(context)) {
return 0;
}
try {
ContentResolver resolver = context.getContentResolver();
int mode = Settings.System.getInt(resolver, "aod_mode", -1);
if(mode != state){
android.provider.Settings.System.putInt(resolver, "aod_mode", state);
}
return 1; //Settings.System.getInt(resolver, "aod_mode", -1);
}
catch (Exception e) {
// no permissions
e.printStackTrace();
return 2;
}
}
#End If