Android Open Source - RootSwitchWidget Switch Widget Provider






From Project

Back to project page RootSwitchWidget.

License

The source code is released under:

MIT License

If you think the Android project RootSwitchWidget listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.misodengaku.rootswitchwidget;
// w  ww .j  av a2s .  c  o  m
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.util.Log;
import android.widget.RemoteViews;
import android.app.PendingIntent;
import android.widget.Toast;

import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class SwitchWidgetProvider extends AppWidgetProvider {

    final String btn1Filter = "com.misodengaku.rootswitchwidget.BUTTON_CLICKED";


  @Override
  public void onEnabled(Context context) {
    Log.v("SwitchWidget", "onEnabled");
    super.onEnabled(context);
  }
  
  @Override
  public void onUpdate(Context context, AppWidgetManager appWidgetManager,
      int[] appWidgetIds) {

    Log.v("SwitchWidget", "onUpdate");
    super.onUpdate(context, appWidgetManager, appWidgetIds);

        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.main);
        // BUTTON1
        Intent btn1Intent = new Intent(btn1Filter);
        PendingIntent btn1Pending = PendingIntent.getBroadcast(context, 0, btn1Intent, 0);
        views.setOnClickPendingIntent(R.id.btn1_id, btn1Pending);
        appWidgetManager.updateAppWidget(appWidgetIds, views);
  }
  
  @Override
  public void onDeleted(Context context, int[] appWidgetIds) {
    Log.v("SwitchWidget", "onDeleted");
    super.onDeleted(context, appWidgetIds);
  }
  
  @Override
  public void onDisabled(Context context) {
    Log.v("SwitchWidget", "onDisabled");
    super.onDisabled(context);
  }

  
  @Override
  public void onReceive(Context context, Intent intent) {
    Log.v("SwitchWidget", "onReceive");
    super.onReceive(context, intent);

        if (checkPuzleAndDragons(context))
        {
            Log.v("SwitchWidget", "????????????????");
            Toast.makeText(context, "????????????????", Toast.LENGTH_LONG).show();
            return;
        }


        String action = intent.getAction();
        if (action.equals(btn1Filter)) {
            Log.v("Widget02", "Button1 Clicked");

            boolean isRooted;
            try {
                Process process = Runtime.getRuntime().exec("su");
                process.destroy();
                isRooted = true;
                Log.v("SwitchWidget", "su is available.");
            } catch (IOException e) {
                //e.printStackTrace();
                Log.v("SwitchWidget", "su is not found.");
                isRooted = false;
            }

            if (isRooted)
            {
                try {
                    Process p = Runtime.getRuntime().exec("su");
                    DataOutputStream dos = new DataOutputStream(p.getOutputStream());
                    dos.writeBytes("mount -o rw,remount /system\n"); // ????
                    dos.writeBytes("mv /system/xbin/su /system/xbin/backupsu\n");
                    dos.writeBytes("mount -o ro,remount /system\n"); // ????
                    Toast.makeText(context, "temp unroot????????????", Toast.LENGTH_LONG).show();
                } catch (IOException e) {
                    e.printStackTrace();
                    Toast.makeText(context, "temp unroot?????????????????", Toast.LENGTH_LONG).show();
                }
            }else
            {
                try {
                    Process p = Runtime.getRuntime().exec("backupsu");
                    DataOutputStream dos = new DataOutputStream(p.getOutputStream());
                    dos.writeBytes("mount -o rw,remount /system\n"); // ????
                    dos.writeBytes("mv /system/xbin/backupsu /system/xbin/su\n");
                    dos.writeBytes("mount -o ro,remount /system\n"); // ????
                    Toast.makeText(context, "root????????????????????????", Toast.LENGTH_LONG).show();
                } catch (IOException e) {
                    e.printStackTrace();
                    Toast.makeText(context, "su???????????", Toast.LENGTH_LONG).show();

                }

            }
        }
  }

    public boolean checkPuzleAndDragons(Context context)
    {
        PackageManager packageManager = context.getPackageManager();
        List<ApplicationInfo> applicationInfo = packageManager.getInstalledApplications(PackageManager.GET_META_DATA);
        for (ApplicationInfo info : applicationInfo) {
            if (info.processName.equals("jp.gungho.pad")){
                return true;
            }
        }
        return false;
    }
}




Java Source Code List

com.misodengaku.rootswitchwidget.BuildConfig.java
com.misodengaku.rootswitchwidget.SwitchWidgetProvider.java