首页 > 其他分享 >Android11 双击亮屏 上层修改

Android11 双击亮屏 上层修改

时间:2022-12-13 21:12:39浏览次数:57  
标签:TAP 亮屏 buffer Android11 MODE device import android 双击

package com.android.systemui.qs.tiles; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.ServiceConnection; import android.os.Handler; import android.os.IBinder; import android.os.Message; import android.os.Messenger; import android.os.RemoteException; import android.os.UserHandle; import android.service.quicksettings.Tile; import android.util.Log; import android.widget.Switch; import android.widget.Toast;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.systemui.R; import com.android.systemui.R.drawable; import com.android.systemui.plugins.qs.QSTile.BooleanState; import com.android.systemui.qs.QSHost; import com.android.systemui.qs.tileimpl.QSTileImpl;
import javax.inject.Inject; import java.io.BufferedWriter; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.FileReader; import java.io.IOException; import java.io.FileInputStream; import java.io.InputStreamReader;
public class DoubletapTile extends QSTileImpl<BooleanState> {     private static final String TAG = "DoubletapTile";     private final Icon mIconen = ResourceIcon.get(drawable.ic_en_touch_app_24); //    private final Icon mIcondis = ResourceIcon.get(drawable.ic_dis_touch_screen_24);     private static final String TAP_MODE_PATH1 = "sys/devices/platform/11007000.i2c0/i2c-0/0-0018/ili_gesture";     private static final String TAP_MODE_PATH2 = "sys/devices/platform/11007000.i2c0/i2c-0/0-0048/cts_gesture";     private static StringBuffer m_lcd_buffer = new StringBuffer();     private QSHost mHost;
    @Inject     public DoubletapTile(QSHost host) {         super(host);         mHost = host;     }
    @Override     public BooleanState newTileState() {         return new BooleanState();     }
    @Override     public Intent getLongClickIntent() {         return null;     }
    @Override     public void handleLongClick() {     }
    @Override     protected void handleClick() {         // mHost.collapsePanels();         updateDoubletapState();         refreshState();     }
    @Override     public CharSequence getTileLabel() {         return mContext.getString(R.string.doubletap);     }
    @Override     protected void handleUpdateState(BooleanState state, Object arg) {         state.value = isDoubletap(); //        state.icon = isDoubletap() ? mIconen :mIcondis;         state.label = getTileLabel();         state.state = isDoubletap() ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE;         state.icon = mIconen;         state.label = mContext.getString(R.string.doubletap);         state.contentDescription = state.label;     }
    @Override     public int getMetricsCategory() {         return MetricsEvent.QS_PANEL;     }
    @Override     public void handleSetListening(boolean listening) {
    }     public void updateDoubletapState() {         if (!isDoubletap()) {             writeValue("1");             Log.w(TAG," writeValue(\"1\")");         } else {             writeValue("0");             Log.w(TAG," writeValue(\"0\")");         }     }
    private boolean isDoubletap(){         String doubletapValue = readDoubletapValue();         Log.d(TAG,"doubletap = " + doubletapValue);         if (doubletapValue.equals("1")) {             return true;         } else {             return false;         }     }
    private synchronized static void writeValue(String value) {         String TAP_MODE_PATH_W;         if(ISFirS()){             TAP_MODE_PATH_W=TAP_MODE_PATH1;         }else{             TAP_MODE_PATH_W=TAP_MODE_PATH2;         }         FileWriter fw = null;         BufferedWriter bw = null;         try {             fw = new FileWriter(TAP_MODE_PATH_W);             bw = new BufferedWriter(fw);             String line = value;             bw.write(line);             bw.flush();             bw.close();             fw.close();         } catch (IOException e) {             e.printStackTrace();         }     }
    private synchronized static String readDoubletapValue() {         String TAP_MODE_PATH_R;         if(ISFirS()){             TAP_MODE_PATH_R=TAP_MODE_PATH1;         }else{             TAP_MODE_PATH_R=TAP_MODE_PATH2;         }         String value = "";         try {             FileInputStream fis = new FileInputStream(TAP_MODE_PATH_R);             InputStreamReader isr = new InputStreamReader(fis);             BufferedReader br = new BufferedReader(isr, 1024);
            StringBuilder buffer = new StringBuilder();             String ch = null;             while ((ch = br.readLine()) != null) {                 buffer.append(ch);                 buffer.append("\r\n");                 return value = ch;             }         } catch (IOException e) {             Log.d(TAG, e.getMessage());         }         return value;     }     private static void getDeviceInfo(String deviceName, StringBuffer device_buffer){         android.util.Log.v("wch","file:" + "device_info/" + deviceName);         try {             FileInputStream fis = new FileInputStream(                     "sys/devices/platform/device_info/" +deviceName);             InputStreamReader isr = new InputStreamReader(fis);             BufferedReader br = new BufferedReader(isr, 4096);             String ch = null;             android.util.Log.v("wch","br:" + br);             while ((ch = br.readLine()) != null){                 device_buffer.append(ch);                 if("ParaVersion".equals(deviceName)){                     device_buffer.append("\n");                 }             }             android.util.Log.v("wch","device_buffer:" + device_buffer);             fis.close();         } catch (FileNotFoundException e) {             device_buffer.append("No" + device_buffer + "file found");             Log.i(TAG, "No lcdinfo file found");         } catch (IOException e) {             device_buffer.append("Error reading " + device_buffer + "file");             device_buffer.append(e);             Log.w(TAG, "Error reading" + device_buffer +" file", e);         }         if (device_buffer != null) {             Log.i(TAG, "the" + device_buffer + "info = " + device_buffer.toString());         }     }     public static boolean ISFirS(){         getDeviceInfo("LCMINFO", m_lcd_buffer);         if(m_lcd_buffer.toString().contains("xc_ili9882q_dsi_vdo_hdplus_ld_p1012")){             return true;         }else {             return false;         }     } }

标签:TAP,亮屏,buffer,Android11,MODE,device,import,android,双击
From: https://www.cnblogs.com/gwj0424/p/16980620.html

相关文章