<commit_before>/* Copyright 2013 <NAME>

 * 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.durka.hallmonitor;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.admin.DevicePolicyManager;
import android.appwidget.AppWidgetManager;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources.NotFoundException;
import android.os.Build;
import android.database.Cursor;
import android.net.Uri;
import android.os.Handler;
import android.os.PowerManager;
import android.preference.PreferenceManager;
import android.provider.BaseColumns;
import android.provider.ContactsContract;
import android.service.notification.StatusBarNotification;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

/**
 * Container Class for various inner Classes which service the capabilities of the HallMonitor app.
 */
public class Functions {
	
	// callback identifiers for startActivityForResult, used by the preference screen
	public static final int DEVICE_ADMIN_WAITING = 42;
	public static final int REQUEST_PICK_APPWIDGET = 9;
	public static final int REQUEST_CONFIGURE_APPWIDGET = 5;
	public static final int NOTIFICATION_LISTENER_ON = 0xDEAD;
	public static final int NOTIFICATION_LISTENER_OFF = 0xBEEF;
	
    //this action will let us toggle the flashlight
    public static final String TOGGLE_FLASHLIGHT = "net.cactii.flash2.TOGGLE_FLASHLIGHT";

    private static final String DEV_SERRANO_LTE_CM10 = "serranolte"; 	// GT-I9195 CM10.x
    private static final String DEV_SERRANO_LTE_CM11 = "serranoltexx"; 	// GT-I9195 CM11.x
	
	//Class that handles interaction with 3rd party App Widgets
	public static final HMAppWidgetManager hmAppWidgetManager = new HMAppWidgetManager();
	
	public static DefaultActivity defaultActivity;
	public static Configuration configurationActivity;
	
	private static boolean notification_settings_ongoing = false;
	public static boolean widget_settings_ongoing = false;
	
	/**
	 * Provides methods for performing actions. (e.g. what to do when the cover is opened and closed etc.)
	 */
	public static class Actions {
		
		//used for the timer to turn off the screen on a delay
        public static Timer timer = new Timer();
        public static TimerTask timerTask;
		
        
        /**
         * Called whenever the cover_closed event is called. Also called from DefaultActivity when the 
         * screen turns on whilst the cover is closed.
         * Switches to the default activity screen and if we are running root enabled boosts the screen sensitivity.
         * After pref_delay milliseconds locks the screen.
         * @param ctx Application context.
         */
		public static void close_cover(Context ctx) {
			
			Log.d("F.Act.close_cover", "Close cover event receieved.");
			
			//save the cover state
			Events.set_cover(true);
			
			
		    // step 1: bring up the default activity window
			//we are using the show when locked flag as we'll re-use this method to show the screen on power button press
			if (!DefaultActivity.on_screen) {
				ctx.startActivity(new Intent(ctx, DefaultActivity.class)
										.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
												| Intent.FLAG_ACTIVITY_NO_ANIMATION
												| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED));
			}
            
			
			//if we are running in root enabled mode then lets up the sensitivity on the view screen
			//so we can use the screen through the window
			 if (PreferenceManager.getDefaultSharedPreferences(ctx).getBoolean("pref_runasroot", false)) {
                 Log.d("F.Act.close_cover", "We're root enabled so lets boost the sensitivity...");

                 if (Build.DEVICE.equals(DEV_SERRANO_LTE_10) || Build.DEVICE.equals(DEV_SERRANO_LTE_11)) {
                     run_commands_as_root(new String[]{"echo module_on_master > /sys/class/sec/tsp/cmd && cat /sys/class/sec/tsp/cmd_result", "echo clear_cover_mode,3 > /sys/class/sec/tsp/cmd && cat /sys/class/sec/tsp/cmd_result"});
                 } else // others devices
                     run_commands_as_root(new String[]{"echo clear_cover_mode,1 > /sys/class/sec/tsp/cmd"});

				 Log.d("F.Act.close_cover", "...Sensitivity boosted, hold onto your hats!");
			 }
			
			//need this to let us lock the phone
			final DevicePolicyManager dpm = (DevicePolicyManager) ctx.getSystemService(Context.DEVICE_POLICY_SERVICE);
			//final PowerManager pm = (PowerManager)ctx.getSystemService(Context.POWER_SERVICE);
			<commit_msg>S4 mini CM11 support (fix typos)<commit_after>/* Copyright 2013 <NAME>

 * 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.durka.hallmonitor;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.admin.DevicePolicyManager;
import android.appwidget.AppWidgetManager;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources.NotFoundException;
import android.os.Build;
import android.database.Cursor;
import android.net.Uri;
import android.os.Handler;
import android.os.PowerManager;
import android.preference.PreferenceManager;
import android.provider.BaseColumns;
import android.provider.ContactsContract;
import android.service.notification.StatusBarNotification;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

/**
 * Container Class for various inner Classes which service the capabilities of the HallMonitor app.
 */
public class Functions {
	
	// callback identifiers for startActivityForResult, used by the preference screen
	public static final int DEVICE_ADMIN_WAITING = 42;
	public static final int REQUEST_PICK_APPWIDGET = 9;
	public static final int REQUEST_CONFIGURE_APPWIDGET = 5;
	public static final int NOTIFICATION_LISTENER_ON = 0xDEAD;
	public static final int NOTIFICATION_LISTENER_OFF = 0xBEEF;
	
    //this action will let us toggle the flashlight
    public static final String TOGGLE_FLASHLIGHT = "net.cactii.flash2.TOGGLE_FLASHLIGHT";

    private static final String DEV_SERRANO_LTE_CM10 = "serranolte"; 	// GT-I9195 CM10.x
    private static final String DEV_SERRANO_LTE_CM11 = "serranoltexx"; 	// GT-I9195 CM11.x
	
	//Class that handles interaction with 3rd party App Widgets
	public static final HMAppWidgetManager hmAppWidgetManager = new HMAppWidgetManager();
	
	public static DefaultActivity defaultActivity;
	public static Configuration configurationActivity;
	
	private static boolean notification_settings_ongoing = false;
	public static boolean widget_settings_ongoing = false;
	
	/**
	 * Provides methods for performing actions. (e.g. what to do when the cover is opened and closed etc.)
	 */
	public static class Actions {
		
		//used for the timer to turn off the screen on a delay
        public static Timer timer = new Timer();
        public static TimerTask timerTask;
		
        
        /**
         * Called whenever the cover_closed event is called. Also called from DefaultActivity when the 
         * screen turns on whilst the cover is closed.
         * Switches to the default activity screen and if we are running root enabled boosts the screen sensitivity.
         * After pref_delay milliseconds locks the screen.
         * @param ctx Application context.
         */
		public static void close_cover(Context ctx) {
			
			Log.d("F.Act.close_cover", "Close cover event receieved.");
			
			//save the cover state
			Events.set_cover(true);
			
			
		    // step 1: bring up the default activity window
			//we are using the show when locked flag as we'll re-use this method to show the screen on power button press
			if (!DefaultActivity.on_screen) {
				ctx.startActivity(new Intent(ctx, DefaultActivity.class)
										.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
												| Intent.FLAG_ACTIVITY_NO_ANIMATION
												| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED));
			}
            
			
			//if we are running in root enabled mode then lets up the sensitivity on the view screen
			//so we can use the screen through the window
			 if (PreferenceManager.getDefaultSharedPreferences(ctx).getBoolean("pref_runasroot", false)) {
                 Log.d("F.Act.close_cover", "We're root enabled so lets boost the sensitivity...");

                 if (Build.DEVICE.equals(DEV_SERRANO_LTE_CM10) || Build.DEVICE.equals(DEV_SERRANO_LTE_CM11)) {
                     run_commands_as_root(new String[]{"echo module_on_master > /sys/class/sec/tsp/cmd && cat /sys/class/sec/tsp/cmd_result", "echo clear_cover_mode,3 > /sys/class/sec/tsp/cmd && cat /sys/class/sec/tsp/cmd_result"});
                 } else // others devices
                     run_commands_as_root(new String[]{"echo clear_cover_mode,1 > /sys/class/sec/tsp/cmd"});

				 Log.d("F.Act.close_cover", "...Sensitivity boosted, hold onto your hats!");
			 }
			
			//need this to let us lock the phone
			final DevicePolicyManager dpm = (DevicePolicyManager) ctx.getSystemService(Context.DEVICE_POLICY_SERVICE);
			//final PowerManager pm = (PowerManager)ctx.getSystemService(Context.POWER_SERVICE);
			
{'fraction_non_alphanumeric': 0.07959860532358194, 'fraction_numerical': 0.006888340845309975, 'mean_word_length': 3.920502092050209, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '810662', 'n_tokens_mistral': 3512, 'n_tokens_neox': 3192, 'n_words': 1037}