feat: add typed data and views with scoped device power
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
package cn.ucvl.zhaodisplay;
|
||||
|
||||
/** Observed RUN and explicit server capabilities; OP never predicts physical state. */
|
||||
final class PhonePowerModel {
|
||||
final int measuredRun,op;final String state;final long checkedAt;final boolean canStart,canShutdown,managed;
|
||||
PhonePowerModel(int run,int op,String state,long checkedAt,boolean canStart,boolean canShutdown,boolean managed){this.measuredRun=run;this.op=op;this.state=state;this.checkedAt=checkedAt;this.canStart=canStart;this.canShutdown=canShutdown;this.managed=managed;}
|
||||
int run(long now){
|
||||
if(checkedAt<=0||now<checkedAt-5||now-checkedAt>45||op<0||op>2)return -1;
|
||||
if(measuredRun==1&&"online".equals(state))return 1;
|
||||
if(measuredRun==0&&"offline".equals(state))return 0;
|
||||
return -1;
|
||||
}
|
||||
boolean may(int operation,long now,boolean submitting){
|
||||
if(!managed||submitting||op!=0)return false;
|
||||
int observed=run(now);
|
||||
return operation==1?observed==0&&canStart:operation==2&&observed==1&&canShutdown;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user