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.app; 18 19 import android.content.Context; 20 21 import com.android.camera.MediaSaverImpl; 22 import com.android.camera.Storage; 23 import com.android.camera.async.MainThread; 24 import com.android.camera.remote.RemoteShutterListener; 25 import com.android.camera.session.CaptureSessionFactory; 26 import com.android.camera.session.CaptureSessionFactoryImpl; 27 import com.android.camera.session.CaptureSessionManager; 28 import com.android.camera.session.CaptureSessionManagerImpl; 29 import com.android.camera.session.PlaceholderManager; 30 import com.android.camera.session.SessionStorageManager; 31 import com.android.camera.session.SessionStorageManagerImpl; 32 import com.android.camera.session.StackSaverFactory; 33 import com.android.camera.settings.SettingsManager; 34 import com.android.camera.util.AndroidContext; 35 import com.android.camera.util.RemoteShutterHelper; 36 37 /** 38 * Functionality available to all modules and services. 39 */ 40 public class CameraServicesImpl implements CameraServices { 41 /** 42 * Fast, thread safe singleton initialization. 43 */ 44 private static class Singleton { 45 private static final CameraServicesImpl INSTANCE = new CameraServicesImpl( 46 AndroidContext.instance().get()); 47 } 48 49 /** 50 * @return a single instance of of the global camera services. 51 */ instance()52 public static CameraServicesImpl instance() { 53 return Singleton.INSTANCE; 54 } 55 56 private final MediaSaver mMediaSaver; 57 private final CaptureSessionManager mSessionManager; 58 private final MemoryManagerImpl mMemoryManager; 59 private final RemoteShutterListener mRemoteShutterListener; 60 private final MotionManager mMotionManager; 61 private final SettingsManager mSettingsManager; 62 CameraServicesImpl(Context context)63 private CameraServicesImpl(Context context) { 64 mMediaSaver = new MediaSaverImpl(context.getContentResolver()); 65 PlaceholderManager mPlaceHolderManager = new PlaceholderManager(context); 66 SessionStorageManager mSessionStorageManager = SessionStorageManagerImpl.create(context); 67 68 StackSaverFactory mStackSaverFactory = new StackSaverFactory(Storage.instance().DIRECTORY, 69 context.getContentResolver()); 70 CaptureSessionFactory captureSessionFactory = new CaptureSessionFactoryImpl( 71 mMediaSaver, mPlaceHolderManager, mSessionStorageManager, mStackSaverFactory); 72 mSessionManager = new CaptureSessionManagerImpl( 73 captureSessionFactory, mSessionStorageManager, MainThread.create()); 74 mMemoryManager = MemoryManagerImpl.create(context, mMediaSaver); 75 mRemoteShutterListener = RemoteShutterHelper.create(context); 76 mSettingsManager = new SettingsManager(context); 77 78 mMotionManager = new MotionManager(context); 79 } 80 81 @Override getCaptureSessionManager()82 public CaptureSessionManager getCaptureSessionManager() { 83 return mSessionManager; 84 } 85 86 @Override getMemoryManager()87 public MemoryManager getMemoryManager() { 88 return mMemoryManager; 89 } 90 91 @Override getMotionManager()92 public MotionManager getMotionManager() { 93 return mMotionManager; 94 } 95 96 @Override 97 @Deprecated getMediaSaver()98 public MediaSaver getMediaSaver() { 99 return mMediaSaver; 100 } 101 102 @Override getRemoteShutterListener()103 public RemoteShutterListener getRemoteShutterListener() { 104 return mRemoteShutterListener; 105 } 106 107 @Override getSettingsManager()108 public SettingsManager getSettingsManager() { 109 return mSettingsManager; 110 } 111 } 112