导航菜单

页面标题

页面副标题

Tasker v6.5.11 - CameraProxy.java 源代码

正在查看: Tasker v6.5.11 应用的 CameraProxy.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package net.dinglisch.android.taskerm;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Resources;
import android.graphics.Point;
import android.hardware.Camera;
import android.media.AudioManager;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.OrientationEventListener;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import com.joaomgcd.taskerm.util.ExtensionsContextKt;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Iterator;
import java.util.List;
import net.dinglisch.android.taskerm.ExecuteService;

public class CameraProxy extends Activity implements Camera.PictureCallback, Camera.AutoFocusCallback, SurfaceHolder.Callback {
    private File s;
    private boolean w;
    private int i = 0;
    private Camera q = null;
    private int r = -1;
    private int t = -1;
    private boolean u = false;
    private BroadcastReceiver v = null;
    private OrientationEventListener x = null;
    SurfaceHolder y = null;
    private Handler z = null;
    private boolean A = false;
    private ExecuteService.v B = null;

    class a extends OrientationEventListener {
        a(Context context, int i) {
            super(context, i);
        }

        @Override
        public void onOrientationChanged(int i) {
            if (i != -1) {
                CameraProxy.this.i = i;
            }
        }
    }

    class b extends BroadcastReceiver {
        b() {
        }

        @Override
        public void onReceive(Context context, Intent intent) {
            CameraProxy.this.u("screenoff", ExecuteService.v.Cancelled);
        }
    }

    class c implements Camera.ErrorCallback {
        c() {
        }

        @Override
        public void onError(int i, Camera camera) {
            r7.G("CameraProxy", "camera error: " + i);
            CameraProxy.this.u("errCallback", ExecuteService.v.Error);
        }
    }

    private static class d extends Handler {
        WeakReference<CameraProxy> a;

        d(CameraProxy cameraProxy) {
            this.a = new WeakReference<>(cameraProxy);
        }

        @Override
        public void handleMessage(Message message) {
            CameraProxy.o(this.a.get());
        }
    }

    public static class e extends Handler {
        WeakReference<CameraProxy> a;

        e(CameraProxy cameraProxy) {
            this.a = new WeakReference<>(cameraProxy);
        }

        @Override
        public void handleMessage(Message message) {
            this.a.get().u("scanHandler", ExecuteService.v.None);
        }
    }

    public enum f {
        Flash,
        Focus,
        Scene,
        White
    }

    private void A(int i) {
        int s;
        Camera.Parameters parameters = this.q.getParameters();
        r7.f("CameraProxy", "update: screenOri: " + i + " old ori " + parameters.get("rotation"));
        if (this.q != null) {
            if (this.r != -1) {
                int s2 = s(i);
                Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
                Camera.getCameraInfo(this.r, cameraInfo);
                int i2 = cameraInfo.facing;
                int i3 = cameraInfo.orientation;
                s = i2 == 1 ? ((i3 - s2) + 360) % 360 : (i3 + s2) % 360;
                r7.f("CameraProxy", "camindex " + this.r + " phone ori " + s2 + " CAMERA ORI: " + i3 + " cam facing: " + i2 + " setrot: " + s);
            } else {
                s = s(i) % 360;
            }
            r7.f("CameraProxy", "new rotation: " + s);
            parameters.setRotation(s);
            try {
                this.q.setParameters(parameters);
            } catch (Exception e2) {
                r7.H("CameraProxy", "setParameters", e2);
            }
        }
    }

    private File d(File file, String str, String str2) {
        Calendar x = bh.x();
        return new File(file, str + "." + bh.i(this, x) + "." + bh.s(x, false) + str2);
    }

    public static Camera e(int i, String str, String str2) {
        try {
            return Camera.open(i);
        } catch (Exception e2) {
            r7.H(str, str2 + ": failed to open camera " + i, e2);
            return null;
        }
    }

    public static Camera f(String str, String str2) {
        try {
            return Camera.open();
        } catch (Exception e2) {
            r7.H(str, str2 + ": failed to open default camera", e2);
            return null;
        }
    }

    public static String g(Camera.Size size) {
        return String.valueOf(size.width) + "x" + String.valueOf(size.height);
    }

    private void h() {
        if (this.q != null) {
            r7.f("CameraProxy", "camera release");
            this.q.release();
            r7.f("CameraProxy", "release done");
            this.q = null;
        }
        this.r = -1;
    }

    public static int i(Resources resources, String str, int[] iArr) {
        int i = 0;
        for (int i2 : iArr) {
            if (vh.h(resources, i2, new Object[0]).equals(str)) {
                return i;
            }
            i++;
        }
        return -1;
    }

    public static int j(int i) {
        int numberOfCameras = Camera.getNumberOfCameras();
        r7.f("CameraProxy", "no cams: " + numberOfCameras);
        int i2 = 0;
        while (true) {
            if (i2 >= numberOfCameras) {
                i2 = -1;
                break;
            }
            Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
            Camera.getCameraInfo(i2, cameraInfo);
            int i3 = cameraInfo.facing;
            r7.f("CameraProxy", "camera index " + i2 + " facing: " + i3 + " wanted facing: " + i);
            if (i3 == i) {
                break;
            }
            i2++;
        }
        r7.f("CameraProxy", "getCameraIndexWithFacing: got " + i2 + " for facing " + i);
        return i2;
    }

    private File k(File file, String str, String str2) {
        Integer num = 0;
        for (File file2 : file.listFiles()) {
            String name = file2.getName();
            if (name.startsWith(str) && name.endsWith(str2)) {
                try {
                    Integer num2 = new Integer(name.substring(str.length(), name.length() - str2.length()));
                    if (num2.intValue() > num.intValue()) {
                        num = num2;
                    }
                } catch (Exception unused) {
                }
            }
        }
        return new File(file, str + Integer.valueOf(num.intValue() + 1) + str2);
    }

    public static List<String> m(f fVar, Camera camera, boolean z) {
        List<String> list = null;
        if (camera == null) {
            r7.k("CameraProxy", "getSupportedModes:" + fVar + ": null cam");
        } else {
            Camera.Parameters parameters = camera.getParameters();
            int ordinal = fVar.ordinal();
            if (ordinal == 0) {
                list = parameters.getSupportedFlashModes();
            } else if (ordinal == 1) {
                list = parameters.getSupportedFocusModes();
            } else if (ordinal == 2) {
                list = parameters.getSupportedSceneModes();
            } else if (ordinal == 3) {
                list = parameters.getSupportedWhiteBalance();
            }
            if (z) {
                camera.release();
            }
        }
        return list;
    }

    public static String[] n(Camera camera, boolean z) {
        String[] strArr = null;
        if (camera == null) {
            r7.k("CameraProxy", "getSupportedPictureSizes: null cam");
        } else {
            List<Camera.Size> supportedPictureSizes = camera.getParameters().getSupportedPictureSizes();
            if (!dq.F(supportedPictureSizes)) {
                strArr = new String[supportedPictureSizes.size()];
                Iterator<Camera.Size> it = supportedPictureSizes.iterator();
                int i = 0;
                while (it.hasNext()) {
                    strArr[i] = g(it.next());
                    i++;
                }
            }
            if (z) {
                camera.release();
            }
        }
        return strArr;
    }

    public static void o(CameraProxy cameraProxy) {
        if (cameraProxy == null) {
            return;
        }
        StringBuilder sb = new StringBuilder();
        sb.append("do take picture, have cam ");
        sb.append(cameraProxy.q != null);
        r7.f("CameraProxy", sb.toString());
        if (cameraProxy.q != null) {
            cameraProxy.w();
            cameraProxy.A(cameraProxy.i);
            try {
                cameraProxy.q.takePicture(null, null, cameraProxy);
            } catch (Exception e2) {
                r7.H("CameraProxy", "takePicture", e2);
                cameraProxy.u("takePicture", ExecuteService.v.Error);
            }
        }
    }

    public static String p(String str, String[] strArr) {
        int i;
        int i2;
        Point r = r(str);
        String str2 = null;
        if (r != null) {
            for (String str3 : strArr) {
                Point r2 = r(str3);
                if (r2 != null && (((i = r2.x) == (i2 = r.x) && r2.y == r.y) || (r2.y == i2 && i == r.y))) {
                    str2 = str3;
                    break;
                }
            }
        } else {
            r7.G("CameraProxy", "bad picture size: " + str);
        }
        r7.f("CameraProxy", str + ": supported: " + str2);
        return str2;
    }

    public static List<String> q(Resources resources, List<String> list, String[] strArr, int[] iArr) {
        ArrayList arrayList = new ArrayList();
        for (String str : list) {
            int length = strArr.length;
            int i = 0;
            int i2 = 0;
            while (true) {
                if (i >= length) {
                    arrayList.add(dq.J3(str));
                    break;
                }
                if (strArr[i].equals(str)) {
                    arrayList.add(vh.h(resources, iArr[i2], new Object[0]));
                    break;
                }
                i2++;
                i++;
            }
        }
        return arrayList;
    }

    public static Point r(String str) {
        String[] split = str.split("x");
        if (split == null || split.length != 2) {
            r7.G("CameraProxy", "pstp: bad format: " + str);
            return null;
        }
        Integer E3 = dq.E3(split[0]);
        Integer E32 = dq.E3(split[1]);
        if (E3 == null || E3.intValue() <= 1) {
            r7.G("CameraProxy", "pstp: bad width: " + split[0]);
            return null;
        }
        if (E32 != null && E32.intValue() > 1) {
            return new Point(E3.intValue(), E32.intValue());
        }
        r7.G("CameraProxy", "pstp: bad height: " + split[1]);
        return null;
    }

    private int s(int i) {
        if (i < 0) {
            return 0;
        }
        return ((i + 45) / 90) * 90;
    }

    private void t(Camera camera, Camera.Parameters parameters, String str) {
        Point point;
        if (TextUtils.isEmpty(str)) {
            return;
        }
        String[] n = n(this.q, false);
        if (n == null) {
            point = r(str);
        } else {
            String p = p(str, n);
            if (p != null) {
                point = r(p);
            } else {
                r7.G("CameraProxy", "unsupported picture size: " + str);
                point = null;
            }
        }
        if (point != null) {
            r7.f("CameraProxy", "setPictureSize " + str);
            parameters.setPictureSize(point.x, point.y);
        }
    }

    public synchronized void u(String str, ExecuteService.v vVar) {
        try {
            r7.f("CameraProxy", "signal & finish: " + str);
            if (this.B == null) {
                this.B = vVar;
                z();
                SurfaceHolder surfaceHolder = this.y;
                if (surfaceHolder != null) {
                    surfaceHolder.removeCallback(this);
                    this.y = null;
                }
                w();
                h();
                if (this.t != -1) {
                    AudioManager audioManager = (AudioManager) oi.d(this, "audio", "CameraProxy", "saf");
                    if (audioManager != null) {
                        dq.K2(this, 1);
                        try {
                            audioManager.setStreamVolume(1, this.t, 0);
                        } catch (Exception e2) {
                            r7.l("CameraProxy", "signalAndFinish: Can't change system volume", e2);
                        }
                    }
                    this.t = -1;
                }
                finish();
                ExecuteService.R7(this, this.B, null);
                if (zq.j("CameraProxy")) {
                    zq.k(this, "CameraProxy");
                }
            } else {
                r7.f("CameraProxy", "skipping, already handled with result " + this.B);
            }
        } catch (Throwable th2) {
            throw th2;
        }
    }

    private boolean v() {
        long j = this.u ? 1000L : 1000 * getSharedPreferences(g6.g, 0).getInt("csnipD", 2);
        r7.f("CameraProxy", "startDelay " + j + "ms");
        if (j == 0) {
            return false;
        }
        d dVar = new d(this);
        this.z = dVar;
        dVar.sendEmptyMessageDelayed(0, j);
        return true;
    }

    private void w() {
        OrientationEventListener orientationEventListener = this.x;
        if (orientationEventListener != null) {
            orientationEventListener.disable();
            this.x = null;
        }
    }

    private void x() {
        Handler handler = this.z;
        if (handler != null) {
            handler.removeMessages(0);
            this.z = null;
        }
    }

    private void y(net.dinglisch.android.taskerm.c cVar, Bundle bundle) {
        String w = cVar.N(1).w();
        String M = bundle == null ? kq.M(this, w) : kq.P(this, w, false, bundle);
        File l = l(g6.b);
        if (l == null) {
            r7.k("CameraProxy", "not taking photo, no dir");
            u("takePhoto:nodir", ExecuteService.v.Error);
            return;
        }
        int v = cVar.x(2).v();
        if (v == 1) {
            this.s = k(l, M, ".jpg");
        } else if (v == 2) {
            this.s = d(l, M, ".jpg");
        } else {
            this.s = new File(l, M + ".jpg");
        }
        int v2 = cVar.x(0).v();
        try {
            int j = j(v2 == 0 ? 0 : 1);
            this.r = j;
            if (j == -1) {
                r7.G("CameraProxy", "facing " + v2 + " specified, but no such camera available");
            } else {
                r7.f("CameraProxy", "try open camera " + this.r);
                this.q = e(this.r, "CameraProxy", c6.TAKE_PHOTO_LABEL);
            }
        } catch (Exception e2) {
            r7.l("CameraProxy", "camera open", e2);
            h();
        }
        Camera camera = this.q;
        if (camera == null) {
            r7.k("CameraProxy", "no camera");
            u("takePhoto:nocam", ExecuteService.v.Error);
            return;
        }
        camera.setErrorCallback(new c());
        Camera.Parameters parameters = this.q.getParameters();
        parameters.set("jpeg-quality", 85);
        String w2 = cVar.N(5).w();
        String M2 = bundle == null ? kq.M(this, w2) : kq.P(this, w2, false, bundle);
        String str = a1.E[cVar.x(9).v()];
        String str2 = a1.D[cVar.x(8).v()];
        String str3 = a1.H[cVar.x(6).v()];
        String str4 = a1.B[cVar.x(7).v()];
        r7.f("CameraProxy", "res " + M2 + " scene mode: " + str3 + " flash mode: " + str2 + " white balance: " + str4);
        try {
            t(this.q, parameters, M2);
        } catch (Exception unused) {
            r7.G("CameraProxy", "setPictureSize " + M2 + " failed");
        }
        try {
            List<String> supportedFlashModes = parameters.getSupportedFlashModes();
            if (dq.F(supportedFlashModes)) {
                r7.f("CameraProxy", "no flash modes supported");
            } else if (dq.j2(str2, supportedFlashModes) == -1) {
                r7.G("CameraProxy", "setFlashMode: unsupported: " + str2);
            } else {
                parameters.setFlashMode(str2);
            }
        } catch (Exception unused2) {
            r7.G("CameraProxy", "setFlashMode " + str2 + " failed");
        }
        try {
            List<String> supportedFocusModes = parameters.getSupportedFocusModes();
            r7.f("CameraProxy", "supported focus: " + dq.x3(supportedFocusModes));
            if (dq.F(supportedFocusModes)) {
                r7.f("CameraProxy", "no focus mode supported");
            } else if (dq.j2(str, supportedFocusModes) == -1) {
                r7.G("CameraProxy", "setFocusMode: unsupported: " + str);
            } else {
                r7.f("CameraProxy", "set focus: " + str);
                parameters.setFocusMode(str);
            }
        } catch (Exception unused3) {
            r7.G("CameraProxy", "setFocusMode " + str + " failed");
        }
        try {
            List<String> supportedSceneModes = parameters.getSupportedSceneModes();
            if (dq.F(supportedSceneModes)) {
                r7.f("CameraProxy", "no scene modes supported");
            } else if (dq.j2(str3, supportedSceneModes) == -1) {
                r7.G("CameraProxy", "setSceneMode: unsupported: " + str2);
            } else {
                r7.f("CameraProxy", "set scene mode: " + str3);
                parameters.setSceneMode(str3);
            }
        } catch (Exception unused4) {
            r7.G("CameraProxy", "setSceneMode " + str3 + " failed");
        }
        try {
            List<String> supportedWhiteBalance = parameters.getSupportedWhiteBalance();
            if (dq.F(supportedWhiteBalance)) {
                r7.f("CameraProxy", "no white balance modes supported");
            } else if (dq.j2(str4, supportedWhiteBalance) == -1) {
                r7.G("CameraProxy", "setWhiteBalance: unsupported: " + str4);
            } else {
                r7.f("CameraProxy", "set white balance: " + str4);
                parameters.setWhiteBalance(str4);
            }
        } catch (Exception unused5) {
            r7.G("CameraProxy", "setWhiteBalance " + str4 + " failed");
        }
        try {
            this.q.setParameters(parameters);
        } catch (Exception e3) {
            r7.H("CameraProxy", "setParameters", e3);
        }
        r7.f("CameraProxy", "add surface callback");
        SurfaceHolder holder = ((SurfaceView) findViewById(2131297539)).getHolder();
        this.y = holder;
        holder.addCallback(this);
    }

    private void z() {
        BroadcastReceiver broadcastReceiver = this.v;
        if (broadcastReceiver != null) {
            try {
                unregisterReceiver(broadcastReceiver);
            } catch (IllegalArgumentException e2) {
                r7.f("CameraProxy", "signalAndFinish: caught " + e2.toString());
            }
            this.v = null;
        }
    }

    public File l(String str) {
        if (!Environment.getExternalStorageState().equals("mounted")) {
            r7.G("CameraProxy", "no storage card present");
            return null;
        }
        File file = new File(Environment.getExternalStorageDirectory(), str);
        if (!file.isDirectory() && !file.mkdirs()) {
            r7.k("CameraProxy", "failed to make dir " + file.toString());
            return null;
        }
        if (file.canWrite()) {
            return file;
        }
        r7.k("CameraProxy", "photodir not writeable: " + file.toString());
        return null;
    }

    @Override
    public void onAutoFocus(boolean z, Camera camera) {
        r7.f("CameraProxy", "got auto-focus, success: " + z);
        v();
    }

    @Override
    public void onCreate(Bundle bundle) {
        int streamVolume;
        super.onCreate(bundle);
        Bundle bundleExtra = getIntent().getBundleExtra("aci");
        Bundle bundleExtra2 = getIntent().getBundleExtra("lvars");
        net.dinglisch.android.taskerm.c cVar = new net.dinglisch.android.taskerm.c(new qi(bundleExtra));
        int j = cVar.j();
        if (j != 101) {
            r7.k("CameraProxy", "bad action code: " + j);
            u("badaction", ExecuteService.v.Error);
            return;
        }
        this.w = cVar.i(3).R();
        this.u = cVar.i(4).R() || kh.d(this);
        r7.f("CameraProxy", "cam: discrete: " + this.u);
        if (this.u) {
            AudioManager audioManager = (AudioManager) oi.d(this, "audio", "CameraProxy", "onCreate");
            if (audioManager != null && (streamVolume = audioManager.getStreamVolume(1)) > 0) {
                if (ji.n()) {
                    if (ji.e(getApplicationContext()) == 3) {
                        r7.f("CameraProxy", "cam: discrete: don't set sysvol, in interrupt mode none");
                    }
                } else if (audioManager.getRingerMode() == 0) {
                    r7.f("CameraProxy", "cam: discrete: don't set sysvol, in silent mode");
                }
                this.t = streamVolume;
                dq.K2(this, 1);
                try {
                    audioManager.setStreamVolume(1, 0, 0);
                } catch (SecurityException e2) {
                    r7.l("CameraProxy", "Couldn't change volume", e2);
                }
            }
        } else {
            getWindow().setFlags(1024, 1024);
            getWindow().requestFeature(1);
            a aVar = new a(this, 2);
            this.x = aVar;
            aVar.enable();
        }
        setContentView(2131493641);
        LinearLayout linearLayout = (LinearLayout) findViewById(2131297324);
        if (!this.u || dq.g() >= 26) {
            getWindowManager().getDefaultDisplay().getSize(new Point());
            linearLayout.setMinimumWidth((int) (r2.x * 0.6d));
            if (this.u) {
                linearLayout.setLayoutParams(new FrameLayout.LayoutParams(2, 2));
                linearLayout.setGravity(85);
            }
        } else {
            linearLayout.setLayoutParams(new FrameLayout.LayoutParams(1, 1));
        }
        if (this.u) {
            zq.e(this, "CameraProxy");
        } else {
            zq.d(this, "CameraProxy", true);
        }
        b bVar = new b();
        this.v = bVar;
        ExtensionsContextKt.V2(this, bVar, new IntentFilter("android.intent.action.SCREEN_OFF"));
        y(cVar, bundleExtra2);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        z();
        w();
        x();
        h();
        this.y = null;
        MyActivity.e0(this, 2131297324);
    }

    @Override
    public void onPause() {
        super.onPause();
        if (isFinishing() || this.A) {
            u("onpause", ExecuteService.v.None);
        }
    }

    @Override
    public void onPictureTaken(byte[] bArr, Camera camera) {
        z();
        boolean z = false;
        if (bArr == null) {
            r7.k("CameraProxy", "no photo data");
        } else {
            try {
                r7.f("CameraProxy", "opc: write " + bArr.length + " bytes to " + this.s);
                FileOutputStream fileOutputStream = new FileOutputStream(this.s);
                BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream, 8192);
                bufferedOutputStream.write(bArr, 0, bArr.length);
                bufferedOutputStream.flush();
                fileOutputStream.close();
                z = true;
                r7.f("CameraProxy", "opc: write done");
            } catch (IOException e2) {
                r7.G("CameraProxy", "couldn't write file: " + e2.getMessage());
            }
        }
        x();
        h();
        if (!z) {
            u("optErr", ExecuteService.v.Error);
        } else if (!this.w) {
            u("optOK", ExecuteService.v.None);
        } else {
            r7.f("CameraProxy", "opc: scan file");
            oh.c(this, this.s, 5000L, new e(this));
        }
    }

    @Override
    protected void onUserLeaveHint() {
        super.onUserLeaveHint();
        this.A = true;
    }

    @Override
    public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i2, int i3) {
    }

    @Override
    public void surfaceCreated(android.view.SurfaceHolder r5) {
        throw new UnsupportedOperationException("Method not decompiled: net.dinglisch.android.taskerm.CameraProxy.surfaceCreated(android.view.SurfaceHolder):void");
    }

    @Override
    public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
    }
}