Home | History | Annotate | Download | only in camera
      1 /*
      2  * Copyright (C) 2015 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.camera;
     18 
     19 import android.app.Activity;
     20 
     21 import com.android.camera.debug.Log;
     22 import com.android.camera.stats.UsageStatistics;
     23 import com.android.camera.util.CameraUtil;
     24 import com.google.common.logging.eventprotos;
     25 
     26 public final class FatalErrorHandlerImpl implements FatalErrorHandler {
     27     private static final Log.Tag TAG = new Log.Tag("FatalErrorHandler");
     28 
     29     private final Activity mActivity;
     30 
     31     public FatalErrorHandlerImpl(Activity activity) {
     32         mActivity = activity;
     33     }
     34 
     35     @Override
     36     public void onMediaStorageFailure() {
     37         Exception ex = new Exception();
     38         // Log a stack trace to be sure we can track the source.
     39         Log.e(TAG, "Handling Media Storage Failure:", ex);
     40 
     41         // Log the error
     42         UsageStatistics.instance().storageWarning(Storage.ACCESS_FAILURE);
     43 
     44         Reason reason = Reason.MEDIA_STORAGE_FAILURE;
     45         boolean finishActivity = reason.doesFinishActivity();
     46         CameraUtil.showError(mActivity, reason.getDialogMsgId(), reason.getFeedbackMsgId(),
     47                 finishActivity, ex);
     48     }
     49 
     50     @Override
     51     public void onCameraOpenFailure() {
     52         Exception ex = new Exception();
     53         // Log a stack trace to be sure we can track the source.
     54         Log.e(TAG, "Handling Camera Open Failure:", ex);
     55 
     56         UsageStatistics.instance().cameraFailure(
     57                 eventprotos.CameraFailure.FailureReason.OPEN_FAILURE, null,
     58                 UsageStatistics.NONE, UsageStatistics.NONE);
     59 
     60         Reason reason = Reason.CANNOT_CONNECT_TO_CAMERA;
     61         boolean finishActivity = reason.doesFinishActivity();
     62         CameraUtil.showError(mActivity, reason.getDialogMsgId(), reason.getFeedbackMsgId(),
     63                 finishActivity, ex);
     64     }
     65 
     66     @Override
     67     public void onCameraReconnectFailure() {
     68         Exception ex = new Exception();
     69         // Log a stack trace to be sure we can track the source.
     70         Log.e(TAG, "Handling Camera Reconnect Failure:", ex);
     71 
     72         UsageStatistics.instance().cameraFailure(
     73                 eventprotos.CameraFailure.FailureReason.RECONNECT_FAILURE, null,
     74                 UsageStatistics.NONE, UsageStatistics.NONE);
     75 
     76         Reason reason = Reason.CANNOT_CONNECT_TO_CAMERA;
     77         boolean finishActivity = reason.doesFinishActivity();
     78         CameraUtil.showError(mActivity, reason.getDialogMsgId(), reason.getFeedbackMsgId(),
     79                 finishActivity, ex);
     80     }
     81 
     82     @Override
     83     public void onGenericCameraAccessFailure() {
     84         Exception ex = new Exception();
     85         // Log a stack trace to be sure we can track the source.
     86         Log.e(TAG, "Handling Camera Access Failure:", ex);
     87 
     88         UsageStatistics.instance().cameraFailure(
     89                 eventprotos.CameraFailure.FailureReason.UNKNOWN_REASON, null,
     90                 UsageStatistics.NONE, UsageStatistics.NONE);
     91 
     92         Reason reason = Reason.CANNOT_CONNECT_TO_CAMERA;
     93         boolean finishActivity = reason.doesFinishActivity();
     94         CameraUtil.showError(mActivity, reason.getDialogMsgId(), reason.getFeedbackMsgId(),
     95                 finishActivity, ex);
     96     }
     97 
     98     @Override
     99     public void onCameraDisabledFailure() {
    100         Exception ex = new Exception();
    101         // Log a stack trace to be sure we can track the source.
    102         Log.e(TAG, "Handling Camera Disabled Failure:", ex);
    103 
    104         // Log the error
    105         UsageStatistics.instance().cameraFailure(
    106                 eventprotos.CameraFailure.FailureReason.SECURITY, null,
    107                 UsageStatistics.NONE, UsageStatistics.NONE);
    108 
    109         Reason reason = Reason.CAMERA_DISABLED_BY_SECURITY_POLICY;
    110         boolean finishActivity = reason.doesFinishActivity();
    111         CameraUtil.showError(mActivity, reason.getDialogMsgId(), reason.getFeedbackMsgId(),
    112                 finishActivity, ex);
    113     }
    114 
    115     @Override
    116     public void handleFatalError(Reason reason) {
    117         Exception ex = new Exception();
    118         // Log a stack trace to be sure we can track the source.
    119         Log.e(TAG, "Handling Fatal Error:", ex);
    120 
    121         boolean finishActivity = reason.doesFinishActivity();
    122         CameraUtil.showError(mActivity, reason.getDialogMsgId(), reason.getFeedbackMsgId(),
    123                 finishActivity, ex);
    124     }
    125 }
    126