Android 来电翻转静音实现源码

1.添加实现文件:

alps\packages\apps\InCallUI\src\com\android\incallui\SensorFunctionServiceIncall.java

/*
 * Copyright (C) 2013 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */

//cbk.flip.func.add
package com.android.incallui;

import android.app.Service;  
import android.content.Context;  
import android.content.Intent;  
import android.hardware.Sensor;  
import android.hardware.SensorEvent;  
import android.hardware.SensorEventListener;  
import android.hardware.SensorManager;  
import android.os.IBinder;  
import android.os.PowerManager; 
import android.media.AudioManager;
import android.util.Log;
import android.content.BroadcastReceiver;

public class SensorFunctionServiceIncall extends Service {      
  
    private static final String LOG_TAG = "InCallActivity/SensorFunctionServiceIncall";  
    private static final float CRITICAL_DOWN_ANGLE = -5.0f;  
    private static final float CRITICAL_UP_ANGLE = 5.0f;  
    private static final int Z_ORATIATION = 2;  
      
    private SensorManager mSensorManager;  
    private Sensor mGsensor;  
    private SensorEventListener mGsensorListener;  
    private PowerManager pm;  
    private int mReverseDownFlg= -1; 

    private int previousMuteMode = -1;

    private boolean mActFlag=false; 
  
    @Override  
    public void onCreate() {  
        super.onCreate();  
        pm = (PowerManager) getSystemService(Context.POWER_SERVICE);  
          
        mSensorManager= (SensorManager) getSystemService(SENSOR_SERVICE);     
        mGsensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);//TYPE_GRAVITY); 

        Log.d(LOG_TAG, "onCreate()...  this = " + this);

		
        mGsensorListener = new SensorEventListener() {  
  
            @Override  
            public void onAccuracyChanged(Sensor sensor, int accuracy) {  
            }  
  
            @Override  
            public void onSensorChanged(SensorEvent event) {  

                //Log.d(LOG_TAG, "onSensorChanged()...  event = " + event);

                Log.d(LOG_TAG, "onSensorChanged()...  event.values[SensorManager.DATA_Z] = " + event.values[SensorManager.DATA_Z]);

                if(event.values[SensorManager.DATA_Z] >= CRITICAL_UP_ANGLE ){ //screen up  first					
                    mReverseDownFlg = 0;  
					
                } else if(event.values[SensorManager.DATA_Z] <= CRITICAL_DOWN_ANGLE 
                			&&mReverseDownFlg ==0){  //screen down next  
                    mReverseDownFlg = 1;							
                }  

                if(mReverseDownFlg ==1){ //screen reverse from up to down
                    if(mActFlag ==false){  
	                    mActFlag = true;  
/*
	                    AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
	                    audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);					
*/

				AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
				if (previousMuteMode == -1)
				{
					previousMuteMode = am.getRingerMode();
					am.setRingerMode(0);
				}
				am.setRingerMode(previousMuteMode);
				previousMuteMode = -1;

	                    Log.d(LOG_TAG, "onSensorChanged()...  mActFlag = " + mActFlag);
                    }
                }		
            }    
       };    
                 
      mSensorManager.registerListener(mGsensorListener, mGsensor, SensorManager.SENSOR_DELAY_GAME);  
    }  
	
      
    @Override  
    public IBinder onBind(Intent arg0) {  
        return null;  
    }  
	
}  
//cbk.flip.func.add


2.添加来电响应位置:

alps\packages\apps\InCallUI\src\com\android\incallui\InCallActivity.java

    @Override
    protected void onStart() {
        Log.d(this, "onStart()...");
        super.onStart();

        // setting activity should be last thing in setup process
        InCallPresenter.getInstance().setActivity(this);

//cbk.flip.func.add
      if (FeatureOption.FLIP_FUNC_SUPPORT) {
	        final boolean gFlipMuteEnabled = Settings.System.getInt(getContentResolver(),
	                Settings.System.FLIP_MUTE_INCOMMING_CALL, 0) != 0;
			
	      if (gFlipMuteEnabled) {
			final Intent i = new Intent(this, SensorFunctionServiceIncall.class);
		        i.setAction("com.android.services.telephony.common.ISensorFunctionServiceIncall");
			this.startService(i);

			//startService(getApplicationContext(), SensorFunctionServiceIncall.class);
	      	}
      	}
//cbk.flip.func.add
		
    }


郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。