1 Commissions 0b9430cee5 ... 929f8e1dcf

Auteur SHA1 Message Date
  chengzhenyu 929f8e1dcf 替换原来的libgphoto框架 6 ans auparavant

+ 1 - 0
app/build.gradle

@@ -79,6 +79,7 @@ android {
79 79
 dependencies {
80 80
     compile project(path: ':common')
81 81
     compile project(path: ':views')
82
+    compile project(path: ':ryc')
82 83
     compile fileTree(include: ['*.jar'], dir: 'libs')
83 84
     compile 'com.jakewharton:butterknife:8.2.1'
84 85
     apt 'com.jakewharton:butterknife-compiler:8.2.1'

BIN
app/libs/armeabi/libhello_jni.so


+ 9 - 1
app/src/main/AndroidManifest.xml

@@ -149,7 +149,15 @@
149 149
         <service android:name=".service.OrderDealService"/>
150 150
 
151 151
         <service android:name=".dslr.CameraService"
152
-            android:process=":camera"/>
152
+            android:process=":camera">
153
+            <intent-filter>
154
+                <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
155
+            </intent-filter>
156
+
157
+            <meta-data
158
+                android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
159
+                android:resource="@xml/device_filter" />
160
+        </service>
153 161
 
154 162
     </application>
155 163
 

+ 0 - 220
app/src/main/java/ai/pai/lensman/App.java

@@ -2,10 +2,7 @@ package ai.pai.lensman;
2 2
 
3 3
 import android.app.Application;
4 4
 import android.content.Context;
5
-import android.widget.Toast;
6 5
 
7
-import com.android.common.utils.FileUnzipTask;
8
-import com.android.common.utils.LogHelper;
9 6
 import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache;
10 7
 import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
11 8
 import com.nostra13.universalimageloader.cache.memory.impl.WeakMemoryCache;
@@ -14,18 +11,9 @@ import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
14 11
 import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
15 12
 import com.nostra13.universalimageloader.utils.StorageUtils;
16 13
 
17
-import java.io.BufferedInputStream;
18
-import java.io.BufferedOutputStream;
19
-import java.io.BufferedReader;
20
-import java.io.DataOutputStream;
21 14
 import java.io.File;
22
-import java.io.FileOutputStream;
23 15
 import java.io.IOException;
24
-import java.io.InputStreamReader;
25
-import java.lang.reflect.Field;
26
-import java.util.ArrayList;
27 16
 
28
-import ai.pai.lensman.db.Preferences;
29 17
 import ai.pai.lensman.utils.Constants;
30 18
 import ai.pai.lensman.utils.PatchManager;
31 19
 import ai.pai.lensman.utils.UrlContainer;
@@ -38,223 +26,15 @@ public class App extends Application{
38 26
         return mInstance;
39 27
     }
40 28
 
41
-    private static final int CAMERA_LIB_VERSION = 1;
42
-
43 29
     @Override
44 30
     public void onCreate() {
45 31
         super.onCreate();
46 32
         mInstance = this.getApplicationContext();
47
-        if(!checkUsbPermission()){
48
-            Toast.makeText(this,R.string.usb_permission_denied,Toast.LENGTH_SHORT).show();
49
-        }
50
-        checkCameraLibs();
51 33
         initImageLoader();
52 34
         new PatchManager().patch(this, UrlContainer.PATCH_CONFIG_URL,Constants.APP_PATCH_DIR+ File.separator+"patch-"+BuildConfig.VERSION_NAME+".dex","ai.pai.lensman.patch.PatchesInfoImpl");
53 35
         noMedia();
54 36
     }
55 37
 
56
-    private boolean checkUsbPermission(){
57
-        LogHelper.d("czy","checkUsbPermission starts");
58
-        Process process = null;
59
-        DataOutputStream os = null;
60
-        try {
61
-            String cmd = "chmod 777 " + getPackageCodePath();
62
-            String cmd1 = "setenforce 0";
63
-            String cmd2 = "chmod -R 0777 /dev/bus/usb" ;
64
-
65
-            process = Runtime.getRuntime().exec("su");
66
-            os = new DataOutputStream(process.getOutputStream());
67
-            os.writeBytes(cmd + "\n");
68
-            os.writeBytes(cmd1 + "\n");
69
-            os.writeBytes(cmd2 + "\n");
70
-            os.writeBytes("exit\n");
71
-            os.flush();
72
-            process.waitFor();
73
-            return true;
74
-        } catch (Exception e) {
75
-            LogHelper.d("czy","checkUsbPermission exception occur -->"+e);
76
-            return false;
77
-        } finally {
78
-            try {
79
-                if (os != null) {
80
-                    os.close();
81
-                }
82
-                process.destroy();
83
-            } catch (Exception e) {
84
-            }
85
-        }
86
-    }
87
-
88
-    public void copyRawLibToSdcard(String dirPath){
89
-        LogHelper.d("czy","copyRawLibToSdcard");
90
-        Field[] raw = R.raw.class.getFields();
91
-        for (Field r : raw) {
92
-            try {
93
-                int id=getResources().getIdentifier(r.getName(), "raw", getPackageName());
94
-                if(r.getName().startsWith("camera")){
95
-                    String path=dirPath+"/"+r.getName()+".so";
96
-                    BufferedOutputStream rawZipWriter = new BufferedOutputStream((new FileOutputStream(new File(path))));
97
-                    BufferedInputStream rawZipReader = new BufferedInputStream(getResources().openRawResource(id));
98
-                    byte[] buff = new byte[20*1024];
99
-                    int len;
100
-                    while( (len = rawZipReader.read(buff)) > 0 ){
101
-                        rawZipWriter.write(buff,0,len);
102
-                    }
103
-                    rawZipWriter.flush();
104
-                    rawZipWriter.close();
105
-                    rawZipReader.close();
106
-                }
107
-            } catch (Exception e) {
108
-                LogHelper.d("czy","copyRawLibToSdcard exception occur -->"+e);
109
-                e.printStackTrace();
110
-            }
111
-        }
112
-
113
-    }
114
-
115
-    private void checkCameraLibs(){
116
-        String tmpLibDirPath = "/mnt/sdcard/lensman";
117
-        File file = new File(tmpLibDirPath);
118
-        file.mkdirs();
119
-        final String unzipPath = tmpLibDirPath+File.separator+"so";
120
-        String rawSoFilePath = tmpLibDirPath + File.separator + "camera.so";
121
-        deleteDir(new File(unzipPath));
122
-        new File(rawSoFilePath).delete();
123
-        if(Preferences.getInstance().getCameraLibVersion()>=CAMERA_LIB_VERSION){
124
-            return ;
125
-        }
126
-        copyRawLibToSdcard(tmpLibDirPath);
127
-
128
-        new FileUnzipTask(rawSoFilePath, unzipPath, new FileUnzipTask.FileUnzipListener() {
129
-            @Override
130
-            public void onUnzipSuccess(String zipFilePath, String unZipDir) {
131
-                LogHelper.d("czy","onUnzipSuccess");
132
-                ArrayList<String> libNames = new ArrayList<>();
133
-                File libDir = new File(unZipDir);
134
-                for(File file : libDir.listFiles()){
135
-                    if(file.isFile()){
136
-                        libNames.add(file.getName());
137
-                    }else if(file.isDirectory()){
138
-                        for(File subFile : file.listFiles()){
139
-                            libNames.add(file.getName()+File.separator+subFile.getName());
140
-                        }
141
-                    }
142
-                }
143
-                Process process = null;
144
-                DataOutputStream os = null;
145
-                try {
146
-                    String cmd0 = "";
147
-                    for(String lib :libNames){
148
-                        if(lib.contains(File.separator)){
149
-                            String folderPath = lib.substring(0,lib.indexOf(File.separator));
150
-                            cmd0+="rm -rf /system/lib/"+folderPath+"\n";
151
-                        }else{
152
-                            cmd0+="rm -f /system/lib/"+lib+"\n";
153
-                        }
154
-                    }
155
-                    LogHelper.d("czy","cmd0="+cmd0);
156
-
157
-                    String cmd = "chmod 777 " + getPackageCodePath();
158
-                    String cmd2 = "chmod -R 0777 /dev/bus/usb" ;
159
-                    String cmd3 = "mount -o rw,remount "+getSystemBlockPath()+" /system" ;
160
-                    String cmd5 = "cp -fr /mnt/sdcard/lensman/so/.  /system/lib" ;
161
-
162
-                    String cmd6 = "" ;
163
-                    for(String lib :libNames){
164
-                        if(lib.contains(File.separator)){
165
-                            String folderPath = lib.substring(0,lib.indexOf(File.separator));
166
-                            cmd6+="chmod 0777 /system/lib/"+folderPath+"\n";
167
-                        }
168
-                        cmd6+="chmod 0777 /system/lib/"+lib+"\n";
169
-                    }
170
-                    LogHelper.d("czy","cmd6="+cmd6);
171
-                    process = Runtime.getRuntime().exec("su"); // 切换到root帐号
172
-                    os = new DataOutputStream(process.getOutputStream());
173
-                    os.writeBytes(cmd + "\n");
174
-                    os.writeBytes(cmd0);
175
-                    os.writeBytes(cmd2 + "\n");
176
-                    os.writeBytes(cmd3 + "\n");
177
-                    os.writeBytes(cmd5 + "\n");
178
-                    os.writeBytes(cmd6 + "\n");
179
-                    os.writeBytes("exit\n");
180
-                    os.flush();
181
-                    process.waitFor();
182
-                    LogHelper.d("czy","camera lib so install success");
183
-                    Preferences.getInstance().setCameraLibVersion(CAMERA_LIB_VERSION);
184
-                } catch (Exception e) {
185
-                    LogHelper.d("czy","camera lib so install error-->"+e);
186
-                } finally {
187
-                    try {
188
-                        if (os != null) {
189
-                            os.close();
190
-                        }
191
-                        new File(zipFilePath).delete();
192
-                        deleteDir(new File(unZipDir));
193
-                        if(process!=null){
194
-                            process.destroy();
195
-                        }
196
-                    } catch (Exception e) {
197
-                        LogHelper.d("czy","error occurs -->"+e);
198
-                    }
199
-                }
200
-            }
201
-
202
-            @Override
203
-            public void onUnzipError(int errorCode, String zipFilePath, String unZipDir) {
204
-                LogHelper.d("czy","onUnzipError");
205
-                new File(zipFilePath).delete();
206
-                deleteDir(new File(unZipDir));
207
-            }
208
-        }).startUnZip();
209
-
210
-    }
211
-
212
-    private String getSystemBlockPath(){
213
-        String path = null;
214
-        Process process = null;
215
-        BufferedReader in = null;
216
-        try {
217
-            String cmd = "mount";
218
-            process = Runtime.getRuntime().exec(cmd);
219
-            in = new BufferedReader(new InputStreamReader(process.getInputStream()));
220
-            String line;
221
-            while ((line = in.readLine()) != null) {
222
-                if(line.contains(" /system")){
223
-                    path = line.substring(0,line.indexOf(" /system"));
224
-                    LogHelper.d("czy","process result ="+line+"\n+");
225
-                }
226
-            }
227
-        } catch (Exception e) {
228
-            LogHelper.d("czy","getSystemBlockAddr exception occur -->"+e);
229
-        } finally {
230
-            try {
231
-                if(in!=null){
232
-                    in.close();
233
-                }
234
-                process.destroy();
235
-            } catch (Exception e) {
236
-            }
237
-        }
238
-        return path;
239
-    }
240
-
241
-    private static boolean deleteDir(File dir) {
242
-        if (dir.isDirectory()) {
243
-            String[] children = dir.list();
244
-            if (children != null) {
245
-                for (int i = 0; i < children.length; i++) {
246
-                    boolean success = deleteDir(new File(dir, children[i]));
247
-                    if (!success) {
248
-                        return false;
249
-                    }
250
-                }
251
-            }
252
-        }
253
-        if (!dir.canRead() || !dir.canWrite()) {
254
-            return false;
255
-        }
256
-        return dir.delete();
257
-    }
258 38
 
259 39
     private void noMedia(){
260 40
         File noMedia = new File(Constants.APP_ROOT_DIR,".nomedia");

+ 1 - 1
app/src/main/java/ai/pai/lensman/db/Preferences.java

@@ -101,7 +101,7 @@ public class Preferences {
101 101
     }
102 102
 
103 103
     public int getCameraQueryInterval(){
104
-        return mPrefs.getInt("interval",50);
104
+        return mPrefs.getInt("interval",1000);
105 105
     }
106 106
 
107 107
     public void clearPrefs(){

+ 194 - 149
app/src/main/java/ai/pai/lensman/dslr/CameraService.java

@@ -3,27 +3,27 @@ package ai.pai.lensman.dslr;
3 3
 
4 4
 import android.app.Service;
5 5
 import android.content.Intent;
6
-import android.os.AsyncTask;
6
+import android.graphics.Bitmap;
7 7
 import android.os.Bundle;
8 8
 import android.os.IBinder;
9 9
 import android.os.Process;
10
-import android.text.TextUtils;
11 10
 
12 11
 import com.android.common.utils.LogHelper;
12
+import com.remoteyourcam.usb.ptp.Camera;
13
+import com.remoteyourcam.usb.ptp.PtpConstants;
14
+import com.remoteyourcam.usb.ptp.PtpService;
15
+import com.remoteyourcam.usb.ptp.model.LiveViewData;
16
+import com.remoteyourcam.usb.ptp.model.ObjectInfo;
13 17
 
18
+import java.util.ArrayList;
14 19
 import java.util.Timer;
15 20
 import java.util.TimerTask;
16 21
 
17 22
 import ai.pai.lensman.db.Preferences;
18 23
 
19
-public class CameraService extends Service {
20
-
21
-    private boolean isInitExecuted;
22
-    private CameraInitTask cameraInitTask;
24
+public class CameraService extends Service implements  Camera.CameraListener, Camera.StorageInfoListener, Camera.RetrieveImageInfoListener{
23 25
 
24 26
     private Timer photoCaptureTimer;
25
-    private String sessionWorkingDirPath;
26
-    private boolean isLastQueryReturned = true;
27 27
 
28 28
     public static final String ACTION_CAMERA_SERVICE_STATUS_CHANGE = "action.ai.pai.lensman.dslr.cameraservice";
29 29
     public static final String EXTRA_STATUS_PART = "status";
@@ -42,14 +42,15 @@ public class CameraService extends Service {
42 42
     public static final int CMD_START_CAPTURE_PHOTO = 9002;
43 43
     public static final int CMD_STOP_CAPTURE_PHOTO = 9003;
44 44
 
45
-    private static final String MSG_TYPE_CAMERA_ERROR = "camero error";//相机错误,可能是线松动了。先exit,然后重新init
46
-    private static final String MSG_TYPE_NOT_INIT = "not init";  //需要初始化
47
-    private static final String MSG_TYPE_NAME_ERROR = "name error";  //继续调用waitforevent
48
-    private static final String MSG_TYPE_TIME_OUT = "time out";  //继续调用waitforevent
49
-    private static final String MSG_TYPE_CREATE_FILE_ERROR = "creat error";//照片文件创建失败
45
+    private PtpService ptp;
46
+    private Camera camera;
47
+    private int[] origin = new int[0];
50 48
 
51
-    private static final int MAX_NO_PHOTO_COUNT = 500;
52
-    private int count = 0;
49
+    @Override
50
+    public void onCreate() {
51
+        super.onCreate();
52
+        ptp = PtpService.Singleton.getInstance(this);
53
+    }
53 54
 
54 55
     @Override
55 56
     public IBinder onBind(Intent intent) {
@@ -59,40 +60,27 @@ public class CameraService extends Service {
59 60
     @Override
60 61
     public int onStartCommand(Intent intent, int flags, int startId) {
61 62
         LogHelper.d("czy","CameraService onStartCommand  ");
62
-        if(intent!=null&&intent.getIntExtra(EXTRA_CMD,0)>0){
63
+        if(camera == null){
64
+            startCamera(intent);
65
+        }else if(intent!=null&&intent.getIntExtra(EXTRA_CMD,0)>0){
63 66
             int cmd = intent.getIntExtra(EXTRA_CMD,0);
64 67
             if(cmd == CMD_EXIT_CAMERA_CONNECTION){
65 68
                 LogHelper.d("czy","CameraService 收到停止进程任务");
66
-                stopCameraService();
69
+                stopCamera();
67 70
             }else if(cmd == CMD_INIT_CAMERA_CONNECTION){
68
-                if(!isInitExecuted){
69
-                    LogHelper.d("czy","CameraService 收到初始化相机任务");
70
-                    count = 0;
71
-                    cameraInitTask = new CameraInitTask();
72
-                    cameraInitTask.execute();
73
-                }else{
74
-                    LogHelper.d("czy","CameraService 相机初始化成功");
71
+                if(camera != null){
75 72
                     Bundle bundle = new Bundle();
76 73
                     bundle.putInt(EXTRA_STATUS_PART,MSG_CAMERA_INIT_SUCCESS);
77 74
                     sendCameraIntent(bundle);
78 75
                 }
79 76
             }else if(cmd == CMD_START_CAPTURE_PHOTO){
80
-                if(isInitExecuted){
77
+                if(camera !=null){
81 78
                     LogHelper.d("czy","CameraService 收到开始拍摄任务");
82
-                    sessionWorkingDirPath = intent.getStringExtra(EXTRA_SESSION_DIR);
83
-                    if(!TextUtils.isEmpty(sessionWorkingDirPath)){
84
-                        startCapture();
85
-                    }
79
+                   startCapture();
86 80
                 }
87 81
             }else if(cmd == CMD_STOP_CAPTURE_PHOTO){
88
-               stopCapture();
89
-            }
90
-        }else{
91
-            if(!isInitExecuted){
92
-                LogHelper.d("czy","CameraService自动重启,初始化相机");
93
-                count = 0;
94
-                cameraInitTask = new CameraInitTask();
95
-                cameraInitTask.execute();
82
+                LogHelper.d("czy","CameraService 收到结束拍摄任务");
83
+                stopCapture();
96 84
             }
97 85
         }
98 86
         return super.onStartCommand(intent, flags, startId);
@@ -100,89 +88,38 @@ public class CameraService extends Service {
100 88
 
101 89
     @Override
102 90
     public void onDestroy() {
91
+        stopCamera();
103 92
         super.onDestroy();
104 93
     }
105 94
 
106
-    private void stopCameraService(){
107
-        count = 0;
95
+    private void startCamera(Intent intent){
96
+        LogHelper.d("czy","CameraService 尝试与相机建立连接");
97
+        ptp.setCameraListener(this);
98
+        ptp.initialize(this, intent);
99
+    }
100
+    private void stopCamera(){
108 101
         LogHelper.d("czy","CameraService stopCameraService  ");
109
-        if(cameraInitTask!=null){
110
-            cameraInitTask.cancel();
111
-        }
112 102
         if(photoCaptureTimer !=null){
113 103
             photoCaptureTimer.cancel();
114 104
             photoCaptureTimer = null;
115 105
         }
116
-        new CameraExitTask().execute();
106
+        ptp.setCameraListener(null);
107
+        ptp.shutdown();
117 108
         stopSelf();
118 109
         Process.killProcess(Process.myPid());
119 110
         System.exit(0);
120 111
     }
121 112
 
122
-    class CameraInitTask extends AsyncTask<Void,Integer,Integer>{
123
-
124
-        private boolean isCancelled = false;
125
-
126
-        public void cancel(){
127
-            isCancelled = true;
128
-        }
129
-
130
-        @Override
131
-        protected Integer doInBackground(Void... params) {
132
-            LogHelper.d("czy","CameraService CameraInitTask  ");
133
-            try{
134
-                return  CameraJNIInterface.getInstance().java_mygpcamerainit();
135
-            }catch (Throwable t){
136
-                t.printStackTrace();
137
-                return -1;
138
-            }
139
-        }
140
-
141
-        @Override
142
-        protected void onPostExecute(Integer result) {
143
-
144
-            if(isCancelled){
145
-                return;
146
-            }
147
-            if(result>=0){
148
-                LogHelper.d("czy","CameraService 相机初始化成功");
149
-                isInitExecuted = true;
150
-                Bundle bundle = new Bundle();
151
-                bundle.putInt(EXTRA_STATUS_PART,MSG_CAMERA_INIT_SUCCESS);
152
-                sendCameraIntent(bundle);
153
-            }else{
154
-                LogHelper.d("czy","CameraService 相机初始化失败,杀掉进程,返回值是"+result);
155
-                Bundle bundle = new Bundle();
156
-                bundle.putInt(EXTRA_STATUS_PART, MSG_CAMERA_CONN_ERROR);
157
-                sendCameraIntent(bundle);
158
-                stopCameraService();
159
-            }
160
-        }
161
-    }
162
-
163
-    class CameraExitTask extends AsyncTask<Void,Integer,Integer>{
164
-
165
-
166
-        @Override
167
-        protected Integer doInBackground(Void... params) {
168
-            try{
169
-                return  CameraJNIInterface.getInstance().java_mygpcameraexit();
170
-            }catch (Throwable t){
171
-                t.printStackTrace();
172
-            }
173
-            return 0;
174
-        }
175 113
 
176
-    }
177 114
     public void startCapture() {
178 115
         stopCapture();
179 116
         photoCaptureTimer = new Timer();
180 117
         photoCaptureTimer.schedule(new TimerTask() {
181 118
             @Override
182 119
             public void run() {
183
-                fetchPhotoTask();
120
+                camera.retrieveImageHandles(CameraService.this, 0xFFFFFFFF, PtpConstants.ObjectFormat.EXIF_JPEG);
184 121
             }
185
-        },1000, Preferences.getInstance().getCameraQueryInterval());
122
+        },0, Preferences.getInstance().getCameraQueryInterval());
186 123
     }
187 124
 
188 125
     public void stopCapture(){
@@ -190,66 +127,174 @@ public class CameraService extends Service {
190 127
             photoCaptureTimer.cancel();
191 128
             photoCaptureTimer = null;
192 129
         }
130
+        origin = new int[0];
193 131
     }
194 132
 
195
-    private void fetchPhotoTask(){
196
-        if(!isLastQueryReturned){
197
-            LogHelper.d("czy","CameraService fetchPhotoTask last query not finished,return ");
198
-            return;
199
-        }
133
+    private void sendCameraIntent(Bundle bundle){
134
+        Intent intent = new Intent(ACTION_CAMERA_SERVICE_STATUS_CHANGE);
135
+        intent.putExtras(bundle);
136
+        sendBroadcast(intent);
137
+    }
200 138
 
201
-        isLastQueryReturned = false;
202
-        String eventMsg = CameraJNIInterface.getInstance().java_mygpcamerawaitforevent(sessionWorkingDirPath);
203
-        LogHelper.d("czy","CameraService mygpcamerawaitforevent return result = "+eventMsg);
204
-        if(eventMsg!=null && eventMsg.length()>0){
205
-            count = 0;
206
-            if(MSG_TYPE_NOT_INIT.equalsIgnoreCase(eventMsg)||MSG_TYPE_CAMERA_ERROR.equalsIgnoreCase(eventMsg)){
207
-                LogHelper.d("czy","CameraService fetchPhotoTask 相机连接错误,重新连接试试");
208
-                Bundle bundle = new Bundle();
209
-                bundle.putInt(EXTRA_STATUS_PART, MSG_CAMERA_CONN_ERROR);
210
-                sendCameraIntent(bundle);
211
-                stopCameraService();
212
-            }else if(MSG_TYPE_TIME_OUT.equalsIgnoreCase(eventMsg)||MSG_TYPE_NAME_ERROR.equalsIgnoreCase(eventMsg)){
213
-                count++;
214
-                if(count>=MAX_NO_PHOTO_COUNT){
215
-                    LogHelper.d("czy","CameraService fetchPhotoTask 太久没发现新照片了,重新连接试试");
216
-                    Bundle bundle = new Bundle();
217
-                    bundle.putInt(EXTRA_STATUS_PART, MSG_CAMERA_CONN_ERROR);
218
-                    sendCameraIntent(bundle);
219
-                    stopCameraService();
139
+
140
+    @Override
141
+    public void onCameraStarted(Camera camera) {
142
+        this.camera = camera;
143
+        LogHelper.d("czy","CameraService 相机初始化成功");
144
+        Bundle bundle = new Bundle();
145
+        bundle.putInt(EXTRA_STATUS_PART,MSG_CAMERA_INIT_SUCCESS);
146
+        sendCameraIntent(bundle);
147
+    }
148
+
149
+    @Override
150
+    public void onCameraStopped(Camera camera) {
151
+        this.camera = null;
152
+        Bundle bundle = new Bundle();
153
+        bundle.putInt(EXTRA_STATUS_PART,MSG_CAMERA_CONN_ERROR);
154
+        sendCameraIntent(bundle);
155
+    }
156
+
157
+    @Override
158
+    public void onNoCameraFound() {
159
+        this.camera = null;
160
+        Bundle bundle = new Bundle();
161
+        bundle.putInt(EXTRA_STATUS_PART,MSG_CAMERA_CONN_ERROR);
162
+        sendCameraIntent(bundle);
163
+    }
164
+
165
+    @Override
166
+    public void onError(String message) {
167
+        camera = null;
168
+        Bundle bundle = new Bundle();
169
+        bundle.putInt(EXTRA_STATUS_PART,MSG_CAMERA_CONN_ERROR);
170
+        sendCameraIntent(bundle);
171
+    }
172
+
173
+    @Override
174
+    public void onPropertyChanged(int property, int value) {
175
+
176
+    }
177
+
178
+    @Override
179
+    public void onPropertyStateChanged(int property, boolean enabled) {
180
+
181
+    }
182
+
183
+    @Override
184
+    public void onPropertyDescChanged(int property, int[] values) {
185
+
186
+    }
187
+
188
+    @Override
189
+    public void onLiveViewStarted() {
190
+
191
+    }
192
+
193
+    @Override
194
+    public void onLiveViewData(LiveViewData data) {
195
+
196
+    }
197
+
198
+    @Override
199
+    public void onLiveViewStopped() {
200
+
201
+    }
202
+
203
+    @Override
204
+    public void onCapturedPictureReceived(int objectHandle, String filename, Bitmap thumbnail, Bitmap bitmap) {
205
+
206
+        LogHelper.d("czy","CameraService fetchPhotoTask new photo found");
207
+
208
+        Bundle bundle = new Bundle();
209
+        bundle.putInt(EXTRA_STATUS_PART, MSG_CAMERA_NEW_PHOTO_FOUND);
210
+        bundle.putString(EXTRA_DATA_PART,filename);
211
+        sendCameraIntent(bundle);
212
+    }
213
+
214
+    @Override
215
+    public void onBulbStarted() {
216
+
217
+    }
218
+
219
+    @Override
220
+    public void onBulbExposureTime(int seconds) {
221
+
222
+    }
223
+
224
+    @Override
225
+    public void onBulbStopped() {
226
+
227
+    }
228
+
229
+    @Override
230
+    public void onFocusStarted() {
231
+
232
+    }
233
+
234
+    @Override
235
+    public void onFocusEnded(boolean hasFocused) {
236
+
237
+    }
238
+
239
+    @Override
240
+    public void onFocusPointsChanged() {
241
+
242
+    }
243
+
244
+    @Override
245
+    public void onObjectAdded(int handle) {
246
+
247
+    }
248
+
249
+    @Override
250
+    public void onLogMessage(String msg) {
251
+
252
+    }
253
+
254
+    @Override
255
+    public void onStorageFound(int handle, String label) {
256
+
257
+    }
258
+
259
+    @Override
260
+    public void onAllStoragesFound() {
261
+
262
+    }
263
+
264
+    @Override
265
+    public void onImageHandlesRetrieved(int[] handles) {
266
+        if(origin.length ==0){
267
+            origin = handles;
268
+        }else{
269
+            if(origin.length == handles.length){
270
+                return;
271
+            }
272
+            ArrayList<Integer> diff = new ArrayList<>();
273
+            for (int i = 0; i < handles.length; i++) {
274
+                boolean isMatch = false;
275
+                for (int j = 0; j < origin.length; j++) {
276
+                    if (origin[j] == handles[i]) {
277
+                        isMatch = true;
278
+                        break;
279
+                    }
220 280
                 }
221
-            }else if(MSG_TYPE_CREATE_FILE_ERROR.equalsIgnoreCase(eventMsg)){
222
-                Bundle bundle = new Bundle();
223
-                bundle.putInt(EXTRA_STATUS_PART, MSG_SDCARD_ERROR);
224
-                sendCameraIntent(bundle);
225
-            }else{
226
-                String sub = eventMsg.substring(0,1);
227
-                if(TextUtils.isDigitsOnly(sub)){
228
-                    LogHelper.d("czy","CameraService fetchPhotoTask new photo found");
229
-                    Bundle bundle = new Bundle();
230
-                    bundle.putInt(EXTRA_STATUS_PART, MSG_CAMERA_NEW_PHOTO_FOUND);
231
-                    bundle.putString(EXTRA_DATA_PART,eventMsg);
232
-                    sendCameraIntent(bundle);
281
+                if (!isMatch) {
282
+                    diff.add(handles[i]);
233 283
                 }
234 284
             }
235
-        }else{
236
-            count++;
237
-            if(count>=MAX_NO_PHOTO_COUNT){
238
-                LogHelper.d("czy","CameraService fetchPhotoTask 太久没发现新照片了,重新连接试试");
239
-                Bundle bundle = new Bundle();
240
-                bundle.putInt(EXTRA_STATUS_PART, MSG_CAMERA_CONN_ERROR);
241
-                sendCameraIntent(bundle);
242
-                stopCameraService();
285
+            if(camera != null && diff.size() >0){
286
+                for(int k = 0; k< diff.size();k++){
287
+                    camera.retrievePicture(diff.get(k));
288
+                }
243 289
             }
290
+            origin = handles;
244 291
         }
245
-
246
-        isLastQueryReturned = true;
247 292
     }
248 293
 
249
-    private void sendCameraIntent(Bundle bundle){
250
-        Intent intent = new Intent(ACTION_CAMERA_SERVICE_STATUS_CHANGE);
251
-        intent.putExtras(bundle);
252
-        sendBroadcast(intent);
294
+    @Override
295
+    public void onImageInfoRetrieved(int objectHandle, ObjectInfo objectInfo, Bitmap thumbnail) {
296
+
253 297
     }
254 298
 
299
+
255 300
 }

+ 21 - 0
app/src/main/res/xml/device_filter.xml

@@ -0,0 +1,21 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<!-- Copyright (C) 2011 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
+<resources>
17
+    <!-- vendor and product ID for EOS 600D -->
18
+    <!-- usb-device vendor-id="1193" product-id="12824" -->
19
+    <!-- usb-device protocol="0" / -->
20
+    <usb-device class="6" subclass="1" protocol="1" />
21
+</resources>

+ 1 - 1
ryc/src/main/java/com/remoteyourcam/usb/ptp/PtpUsbService.java

@@ -101,7 +101,7 @@ public class PtpUsbService implements PtpService {
101 101
             }
102 102
             camera.shutdownHard();
103 103
         }
104
-        UsbDevice device = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
104
+        UsbDevice device = intent == null ? null :(UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
105 105
         if (device != null) {
106 106
             if (AppConfig.LOG) {
107 107
                 Log.i(TAG, "initialize: got device through intent");